• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

Simplifying the real values

Status
Not open for further replies.
Level 3
Joined
Feb 15, 2015
Messages
26
Hi! I currently work on floating texts to show information to the player. The problem is, when I display the real valuables that are something like 3.25, 4.17,... the system always add unnecessary 0s to them (for example 3.25000, 4.17000). I want to know the way to get rid of these 0s, so that when the value is displayed, it only shows 3.25 instead of 3.25000, for example)
 
I presume it uses the same number of digits after the decimal place each time, so you can just subtract off the last 4 characters of the string with a SubString() call:
  • Set YourStr = String(number)
  • Set YourStr = SubString(YourStr, 1, (Length of YourStr) - 4)


If it's not always 6 digits past the decimal you can do this: Multiply the numbers by 100, convert them to integers, then to strings, and then insert a period 2 characters from the end:
  • Set YourReal = 1035.2985
  • Set YourStr = String(Integer(YourReal x 100.00))
  • Set Len = Length of YourStr
  • Set YourStr = SubString(YourStr, 1, Len-2) + "." + SubString(YourStr, Len-1, Len)
This will fail if the absolute value of YourReal is less than 1.
 
Last edited:
Status
Not open for further replies.
Back
Top