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
Written by Fendy Kusuma Wardhana
Related protips
1 Response
Why ?
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Js
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#