javascript number if .00 truncate
Number.prototype.toFixedDown = function(digits) {
var re = new RegExp("(\\d+\\.\\d{" + digits + "})(\\d)"),
m = this.toString().match(re);
return m ? parseFloat(m[1]) : this.valueOf();
};
[ 5.467.toFixedDown(2),
985.943.toFixedDown(2),
17.56.toFixedDown(2),
(0).toFixedDown(1),
1.11.toFixedDown(1) + 22];
// [5.46, 985.94, 17.56, 0, 23.1]
Also in JavaScript:
- include js in html
- node js else
- How do you select a particular option in a SELECT element in jQuery?
- javascript to string
- javascript add 1 to each element in array
- javascript copy items into another array
- Javascript clear canvas
- login form validation using pattern in angular
- site "src="https://cdnjs.cloudflare.com/ajax/libs/popper.js"
- if button is keeping pressed execute increment javascript
- map with async
- Property 'find' does not exist on type NodeListOf
- js onscroll event
- click a link using jquery
- js window redirect
- how sent data to dilaog angular material
- jquery get base url
- delete first character javascript
- Exception in thread "main" org.openqa.selenium.JavascriptException: cannot read getPlayerState
- flutter reorder map by key
- react project ideas
- change bloodhound remote dynamically
- check if isset variable js
- how to use a fixed time zone in nodejs