Click here to Skip to main content
15,892,768 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to round a double value to the lowest quarter in c#?

double value 12.44 should round to 12.25,
12.20 to 12
12.60 to 12.50
11.30 to 11.25


I have use following formula to round up the value.
It returns 12.60 to 12.50 but not 12.44 to 12.25

Math.Round(12.44 * 4 / 4) = 12.50

Thank you.
Posted

Use Floor instead of Round.
C#
double number = 12.44;
double result = Math.Floor(number * 4) / 4;
 
Share this answer
 
Comments
Thomas Daniels 31-Mar-15 14:50pm    
+5
Try this:
C#
// where "d" is your double
double lowestQuarter = Math.Floor(4 * d) / 4;

Results:
12.20 -> 12
12.60 -> 12.5
11.30 -> 11.25
9.90  -> 9.75
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900