Jump to content

Recommended Posts

Posted (edited)

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
Posted

Why not using String()?

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

  On 10/15/2011 at 10:33 AM, guinness said:

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...

Posted

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.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

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 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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...