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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I believe you want to use
Math.Truncate()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.Floorwill always round down towards negative infinity. Here’s a post on the difference between the two.