Javascript – Parsing float

ShaunJavascript0 Comments

Javascript development

Javascript

Parse Float with commas

When dealing with calculations around pricing, it is important to ensure when using parseFloat in JavaScript that it doesn’t malform the result.

The function below checks your number if it contains commas, strips them out, parses float to 2 decimal places, then adds the commas back in:

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *