javascript - Round decimal place only to 3 places -


i need round decimal places three:

here code:

var split_arr = subtotal_string.split(".", subtotal_string); var integer = split_arr[0]; var decimal = split_arr[1];  var decimal_new = decimal.tofixed(3); 

but not working..

please help, thanks

you don't need split it, cast string number (+) call tofixed():

var threedp = (+subtotal_string).tofixed(3); // 9.43663436 -> 9.437  

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -