Last Updated: February 25, 2016
·
7.558K
· danzkusuma

Make 2 number decimal (trim not rounded) in JS

We are very often dealing with number in JS or Jquery, especially in chart. when we have a data example like this :

var point = 123,3504537282397;

that is a long decimal number. We want to trim it.. not rounded or else. The different between is, Trim 2 number decimal will result 123,35 (as expected) and Rounded will result 123,50 or 123,00. So the solution is :

var point = 123,3504537282397;
var newPoint = Math.floor(point * 100) / 100;   //= 123.35

:D

1 Response
Add your response

Why ?

over 1 year ago ·