Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

round up nearest 0.10

Tags:

I need to round up to the nearest 0.10 with a minimum of 2.80

 var panel;
 if (routeNodes.length > 0 && (panel = document.getElementById('distance')))   
 {              
   panel.innerHTML = (dist/1609.344).toFixed(2) + " miles = £" + (((dist/1609.344 - 1) * 1.20) + 2.80).toFixed(2); 
 }

any help would be appreciated

like image 465
Tuffy G Avatar asked Feb 05 '10 09:02

Tuffy G


People also ask

What is 0.5 rounded up?

0.5 rounded off to the nearest whole number is 1. Since, the value after decimal is equal to 5, then the number is rounded up to the next whole number. Hence, the whole number of 0.5 will be 1.

How do you round up to 10?

If the number you are rounding is followed by 5, 6, 7, 8, or 9, round the number up. Example: 38 rounded to the nearest ten is 40. If the number you are rounding is followed by 0, 1, 2, 3, or 4, round the number down. Example: 33 rounded to the nearest ten is 30.

What is 1.5 rounded up?

Rounding Whole NumbersEdit Following the same logic, one could round to the nearest whole number. For example, 1.5 (pronounced as "one point five" or "one and a half") would be rounded up to 2, and 2.1 would be rounded down to 2.


1 Answers

var number = 123.123;

Math.max( Math.round(number * 10) / 10, 2.8 ).toFixed(2);
like image 136
James Avatar answered Jan 03 '23 17:01

James