The Numeral.js JavaScript Library PRO

The Numeral.js JavaScript library assists us with getting the required formats for the numbers our program uses.

The following code sample shows how simple it is to use this library in order to manipulate the format of the numeric values we use in our code.

<!DOCTYPE html>
<html>
<head>
    <title>numeral.js demo</title>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/numeral.js/1.4.5/numeral.min.js">
    </script>
</head>
<body>
<script type="text/javascript">
document.write("<h4>format samples</h4>");
var str;
//numbers
str = numeral(123002132.23423).format('0,0');
document.write("str="+str);
//currency
str = numeral(123002132.23423).format('$0,0.00');
document.write("<br/>str="+str);
//bytes
str = numeral(123002132.23423).format('0b');
document.write("<br/>str="+str);
//percentages
str = numeral(1.25).format('0%');
document.write("<br/>str="+str);
//time
str = numeral(214).format('00:00:00');
document.write("<br/>str="+str);
document.write("<h4>unformat samples</h4>");
str = numeral().unformat('124k');
document.write("str="+str);
str = numeral().unformat('($800,000)');
document.write("<br/>str="+str);
</script>
</body>
</html>

The following video clip overviews this code sample, explains each and every part of it and shows its execution.

You can find more video clips, code samples and training material for learning this library in my free online courses website at http://abelski.lifemichael.com.

Share:

banner for the css playlist in hebrew life michael courses for programmers

The First Steps in CSS

Learn CSS using our our videos (in Hebrew) on the CSS (he) playlist on youtube. Do it now. Do it for free.

Good Trainers Collaborate with Others

It is always essential to keep an open mind and learn from others. This applies to everyone, including teachers and especially software development trainers. Software

The Beauty of Code

Coding is Art! Developing Code That Works is Simple. Develop Code with Style is a Challenge!

Update cookies preferences