I've been putting together an app that contains several calculators for medical equations, but one problem I've run into is that when I perform a calculation, the answer that gets spit out is in scientific format with about 15 decimal points (ex. 6.5 becomes 6.500000000000001e1). I'd like to round it to the nearest 2 decimal places. I know there is the Math.round function, but it looks like that rounds to the nearest integer, and the "string extraction" workarounds I've seen posted on the forums don't seem to do the trick either. Can anyone suggest something relatively simple to truncate the unwanted decimal points? Thanks.
6.500000000000001e1.toFixed(2) => "65.00"
parseFloat(Math.round(YOUR_VARIABLE * 100) / 100).toFixed(2); this works...
Think you can help? Login to answer this question!