I'm using c#, every time i insert 3 decimal places, the number gets rounded e.g.
1.538
rounds
to 1.54
I want the number to be as is e.g. 1.53 (to two decimal places only without any roundings).
How can i do it?
I believe you want to use Math.Truncate()
float number = 1.538
number = Math.Truncate(number * 100) / 100;
Truncate will lop off the end bit. However, bear in mind to be careful with negative numbers.
It depends on whether you always want to round towards 0, or just lop off the end, Math.Floor
will always round down towards negative infinity. Here's a post on the difference between the two.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With