Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript truncate decimal without rounding

// truncate function
// in this example the default value is 2
function truncate(number, index = 2) {
  	// cutting the number
    return +number.toString().slice(0, (number.toString().indexOf(".")) + (index + 1));
}

// example
console.log(truncate(1234.56789, 3)); // 1234.567
Comment

javascript decimals without rounding

function getFlooredFixed(v, d) {
    return (Math.floor(v * Math.pow(10, d)) / Math.pow(10, d)).toFixed(d);
}

var x = 2.305185185185195;

document.write(getFlooredFixed(x, 5));
Comment

PREVIOUS NEXT
Code Example
Javascript :: mongodb aggregate node.js 
Javascript :: img src in react js 
Javascript :: how to change color on js 
Javascript :: pass props in link next js 
Javascript :: every method javascript 
Javascript :: how to loop an object in javascript 
Javascript :: cancel axios request 
Javascript :: check if numbers are consecutive javascript 
Javascript :: download jquery 
Javascript :: iterate object 
Javascript :: Reverse a String With Built-In Functions 
Javascript :: javascript array move element one position 
Javascript :: camelcase to normal text javascript 
Javascript :: javascript eval passing variable 
Javascript :: rounding number to x decimals javascript 
Javascript :: foreach jas 
Javascript :: bodyparser deprecated vscode 
Javascript :: redirect all request http to https express js 
Javascript :: data not write in file node js 
Javascript :: jquery select dropdown option 
Javascript :: dynamic loop variable .each create hash javascript 
Javascript :: nodejs user input 
Javascript :: deserialize json jquery 
Javascript :: days array javascript 
Javascript :: how to set a string 
Javascript :: Javascript console log a string 
Javascript :: js string reverse exception 
Javascript :: js trim all spaces 
Javascript :: vue cors 
Javascript :: check css property jquery 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =