Jump to content

Recommended Posts

Posted

Hello

I know "StringFormat is my friend" but I can't figure this one out.  If $i = 1, how can I get the script to display $i as "1.000"?

Here is a sample of my code:

FileWrite ($file1, Round ((_Timer_Diff ($time1))/1000, 3))

The problem is that if the time in seconds is e.g. 1.0000001, then just "1" is written to the file instead of "1.000".

I could pack this out and add an Int check:

$number1 = Round ((_Timer_Diff ($time1))/1000)
If $number1 = Int ($number1) Then $number1 = $number1 & ".000"
FileWrite ($file1, $number1)

...but I was hoping for a one-line solution.

Thanks

Samuel

Posted (edited)

%i means integer.  If you want decimal places, then you want %f (floating point).

Example:

ConsoleWrite(StringFormat("%.3f", 1) & @CRLF)

%.3f means show the provided number rounded to 3 decimal places.  So if the number was 2.3456, the result would be 2.346.

Edited by TheXman
Posted

I went through the same.

The problem is that a number is a number is number... 

0 = 0.0 = 0.00

The problem is that the computer doesn't understand why you want all those meaningless zeros...  😕

 

What you want is a text representation which is human friendly :)

That is why the string format suggestions above are correct: you want to force a 0.00 text display, which is not a number ;)

 

Skysnake

Why is the snake in the sky?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...