leuce Posted August 18, 2020 Posted August 18, 2020 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
TheXman Posted August 18, 2020 Posted August 18, 2020 (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 August 18, 2020 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
Skysnake Posted August 20, 2020 Posted August 20, 2020 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?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now