Working with float point vaues

Recommended Posts

This is a simple problem I can't find any documentation on, I need to work with a value that is 0.0008, but when the value is displayed or written to a file, it removes all the zeros and the period, that needs to be avoided, how can I go about this?

Also, I wold like to know how to avoid removing all zeros in a numerical string as proceeding zeros are also mysteriously pruned.

```\$Z = "0."
\$D = 4; dictates how many zeros are before the 8
For \$I = 0 To \$D
\$Z += "0"
Next
\$Z += "8"
MsgBox(0,"",\$Z)```
Edited by THAT1ANONYMOUSEDUDE

Share on other sites

Why not using String()?

Thanks, but I just made a stupid, how do I delete this embarrassing thread?

I was supposed to be using the "&" operator instead of the "+", obviously you cannot "add" a zero to zero...

Share on other sites

I'm happy you solved it, but I don't think this thread should be deleted because you posted quickly before actually debugging your code.

Share on other sites

Here are three methods to return the required 0.00008 for fun.

Looking at the last method, instead of using the _StringRepeat() UDF, a one-liner, string repeat routine is used.

```\$Z = "0."
\$D = 4 ; Number of zeros before the 8
For \$I = 1 To \$D
\$Z &= "0"
Next
\$Z &= "8"
MsgBox(0, "A String", \$Z)

; Or

\$Z1 = 8
MsgBox(0, "StringFormat", StringFormat("%." & (\$D + StringLen(\$Z1)) & "f", \$Z1 / 10 ^ (\$D + StringLen(\$Z1))))

; or

MsgBox(0, 'String with string, "0", repeat routine', "0." & StringReplace(StringFormat("%" & \$D & "s", " "), " ", "0") & \$Z1)
; Modified StringRepeatRE from http://www.autoitscript.com/forum/index.php?showtopic=101594&view=findpost&p=722113

ConsoleWrite(StringReplace(StringFormat("%" & 50 & "s", " "), " ", "<>") & @LF) ; Repeat Routine repeats 50 "<>" characters.

;All 3 MsgBoxes return 0.00008```

Create an account

Register a new account