Jump to content

Number() function to generate leading zero


Recommended Posts

Hi Experts,

Good day!

I have this small issue on how to add leading zeros to the result given by "$Sum = Number(GUICtrlRead($Input1) - 111)". I have my $Input1 = 117, now when using number() it will result to "6" instead  of "006". It's just to compute 117 - 111 which should have the result of "006". Is this possible or is there any way to have that kind of result?

 

Thanks, Experts!

KS15

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Link to comment
Share on other sites

The StringRight() function can be used.

And here is another StringFormat()  example.

MsgBox(0, "Leading zeros", StringRight("000" & (117 - 111), 3)) ; Returns 006 (3 characters from the right)

; Or

MsgBox(4096, "Leading zeros", StringFormat("4 characters with leading zeros %04i\n3 characters with leading zeros %03i\n2 characters with leading zeros %02i", 8, 117 - 111, 5))
#cs ; Returns :-
    4 characters with leading zeros 0008
    3 characters with leading zeros 006
    2 characters with leading zeros 05
#CE
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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