Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

set to 2 decimals javascript

(<number>).toFixed(<Number of decimal places required>);
Comment

add decimals javascript

Use toFixed to convert it to a string with some decimal places shaved off, and then convert it back to a number.

+(0.1 + 0.2).toFixed(12) // 0.3

It looks like IE's toFixed has some weird behavior, so if you need to support IE something like this might be better:

Math.round((0.1 + 0.2) * 1e12) / 1e12
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to compare arrays in js 
Javascript :: Heroku H10-App Crashed Error 
Javascript :: location.reload() js 
Javascript :: usememo react 
Javascript :: javascript foreach break 
Javascript :: delete last character from string js 
Javascript :: jest Your test suite must contain at least one test. 
Javascript :: external script in react 
Javascript :: nuxt plugin 
Javascript :: object to map javascript 
Javascript :: palindrome number in javascript 
Javascript :: node js require all function from another file 
Javascript :: javaScript (DOM) HTML Element by Id 
Javascript :: copy element jquery 
Javascript :: create new connection in mongoose 
Javascript :: javascript filter array multiple values 
Javascript :: length of list in javascript 
Javascript :: how to get duplicate values from array in javascript 
Javascript :: javascript remove object from array 
Javascript :: javascript date double digit month 
Javascript :: html content in jspdf 
Javascript :: javascript bind this to anonymous function 
Javascript :: discord.js clear console 
Javascript :: compare objects 
Javascript :: change text shadow javascript 
Javascript :: random color 
Javascript :: how to auto update package.json 
Javascript :: document on click not working 
Javascript :: use $ instead of jQuery 
Javascript :: model mongoose 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =