1

I have four number formats '123 456,78', '123.456,78', '123'456.78', '123,456.78' in my application with dynamic decimal point. Is there any library or method in Javascript to Format number and remove format method?

1
  • Format how exactly, what do you expect to get ? Commented Nov 15, 2014 at 5:47

2 Answers 2

2

You can use Numeral.js

<script src="//cdnjs.cloudflare.com/ajax/libs/numeral.js/1.4.5/numeral.min.js"></script>

var string = numeral(1000).format('0,0');
// '1,000'
Sign up to request clarification or add additional context in comments.

Comments

0

You have several functions on the Number class that give you formatting of numbers:

var n = 5.1234567;
var sf = n.toFixed();
var se = n.toExponential();
var sp = n.toPrecision();

You can find details about these functions here:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision

More or less, these are equivalent to the %f and %g in C/C++ printf() format with just a size representing the number of digits to display.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.