Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript or Jquery rounding up to 1 decimal place

I need to round up to 1 decimal place

If my number is 80.02 I need it to be 80.1.

tried

Math.ceil( (80.02).toFixed(1) ) but this rounds the number up to 81

How can I achieve this?

like image 536
LeBlaireau Avatar asked Nov 26 '13 09:11

LeBlaireau


People also ask

How do you round up decimals in jQuery?

To round off decimal values using jQuery, we can use the built-in JavaScript methods toFixed() or toPrecision(). The toFixed() method converts a number into a string, keeping a specified number of decimals. The toPrecision() method formats a number to a specified length.

Does JavaScript round up or down?

Definition and Usage. The Math. floor() method rounds a number DOWN to the nearest integer.


2 Answers

use Math.ceil( number * 10 ) / 10; for rounding off

for fixing it to one decimal place

(Math.ceil( number * 10 ) / 10).toFixed(1);

Working Fiddle

like image 128
Milind Anantwar Avatar answered Oct 13 '22 23:10

Milind Anantwar


I think it should work perfectly:

parseFloat(13.2*13.23).toFixed(1)

output:174.6

for your 80.02 - 80.0 and for 80.06-80.1 which is good

like image 34
Ashish Avatar answered Oct 14 '22 01:10

Ashish