• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

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)
 
Level 39
Joined
Feb 27, 2007
Messages
5,031
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.
Top