12-19-2011 10:40 AM
Hello team,
I am trying get a number, pad it with up to 3 zeros on the left and keep two decimal points of it.
ie: if the number is 6.25 i want it to be string "006.25"
if it is 60.125 i want it to be "060.12" (round the decimal to nearest hundredth)
I tried using the "Format Into String" with differnet variations of "%03d" and ".2f". but i cannot seem to have a the right combination of both of them in one command. Am I missing something here?
Using LV2011
Thanks
Solved! Go to Solution.
12-19-2011 10:49 AM
Have you tried %06.2f?
12-19-2011 10:51 AM - edited 12-19-2011 10:54 AM
Joseph has the right idea, but it should be %006.2f as the format string.
I tried %06.2f again and see it actually does work.
12-19-2011 10:53 AM
Actually Joseph Loo got it right.
Many thanks, I was thinking inside the box 😞
Cheers 🙂 and thanks once again
12-19-2011 10:54 AM
000.2f does not add the zeros before the number.
12-19-2011 11:50 AM
@Klimovitsky wrote:
000.2f does not add the zeros before the number.
This is expected behavior, in %06.2f the 6 is the minimum field width, The 0 says to pad with 0 to the left to get the minimum field width and .2f specifies to use 2 digits in the decimal part. In %000.2f the minimum field width is 0 so the result will be your number with 2 decimal digits (no padding to the left is necessary).
When you use %06.2f with 6.25 you have: 2 decimal digit, the decimal point and number 6, this correspond to a width of 4. So to get to the minimum field width of 6 two zeros are added to the left.
Ben64
12-19-2011 11:52 AM
Thats what I thought too 🙂
Thanks