Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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]
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to clone an object in javascript 
Javascript :: create or update in sequelize 
Javascript :: how set type of string value to number in js 
Javascript :: how to do jest unit test in react 
Javascript :: nodejs global 
Javascript :: how to check if email already exists in database using javascript 
Javascript :: byte to integer js 
Javascript :: js array push 
Javascript :: js regex find 
Javascript :: how to use nodemailer 
Javascript :: Error: ENOENT: no such file or directory, lstat ode_modules@react-navigationcoresrcgetStateFromPath.tsx 
Javascript :: node localstorage 
Javascript :: what is morgan in nodejs 
Javascript :: datatble tab bootstrap 4 
Javascript :: javascript replace tag 
Javascript :: Add remove link dropzone 
Javascript :: get node degree networkx 
Javascript :: attr.disabled not working in angular 
Javascript :: javascript inheritence 
Javascript :: sort algorithm for array of objects in js 
Javascript :: Check if instance is array 
Javascript :: $$ promise then 
Javascript :: javscript rename property name 
Javascript :: string splice 
Javascript :: discord.js buttons 
Javascript :: document.getanimation 
Javascript :: flat function javascript 
Javascript :: concat 
Javascript :: how to use javascript to hide content and show through link 
Javascript :: angularjs 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =