Originally posted by: amdfanboy
Also , you could use some creative math and casting to cut the numbers off
Psudocode:
1) Store 94.2904 as float in myFloat
2) Multiply it by 100 and store the result back in myFloat
3) Cast it to an integer to truncate the numbers to the right of the decimal place, store as intVal
4) Store the value in intVal as a double in myFloat
5) Divide myFloat by 100 and store it in myFloat
You should now have 94.29 in myFloat
Originally posted by: Jumpem
Cool. Can you explain what that's doing or point me to someplace good?
Originally posted by: HJB417
Originally posted by: Jumpem
Cool. Can you explain what that's doing or point me to someplace good?
NumberFormatInfo Class
I did the 'Fixed-point format', and I also had a digit (2 and 3 in the above example) to tell it how many digits to output. What I stated is the simplest way to do what you want
someDouble.ToString("Fx") where X is the number of digits on the right hand side you want ouputed, in your case, 2 or 3.
someDouble.ToString("F2");
someDouble.ToString("F3");
Originally posted by: amdfanboy
Also , you could use some creative math and casting to cut the numbers off
Psudocode:
1) Store 94.2904 as float in myFloat
2) Multiply it by 100 and store the result back in myFloat
3) Cast it to an integer to truncate the numbers to the right of the decimal place, store as intVal
4) Store the value in intVal as a double in myFloat
5) Divide myFloat by 100 and store it in myFloat
You should now have 94.29 in myFloat
Originally posted by: torpid
What the... why do all the work manually when you have a function library that does it for you? Doesn't make any sense...
Originally posted by: Jumpem
Originally posted by: HJB417
Originally posted by: Jumpem
Cool. Can you explain what that's doing or point me to someplace good?
NumberFormatInfo Class
I did the 'Fixed-point format', and I also had a digit (2 and 3 in the above example) to tell it how many digits to output. What I stated is the simplest way to do what you want
someDouble.ToString("Fx") where X is the number of digits on the right hand side you want ouputed, in your case, 2 or 3.
someDouble.ToString("F2");
someDouble.ToString("F3");
Thanks. Does it do any rounding when it truncates?
