Thousand separator in numeric type literals

Axel Rauschmayer axel at rauschma.de
Mon Apr 30 08:55:38 PDT 2012


+1

Java has started to allow the underscore in numeric literals. JavaScript should do the same. For binary numbers, you’ll usually prefer groups of four. For hex numbers, probably, too. That’s why one should not restrict (much) where the underscore is allowed.

On Apr 30, 2012, at 9:14 , Biju wrote:

> One of the issue in most programming languages is, they dont have a
> mechanism to insert Thousand separators in numeric literals.
> 
> Recently, at work I have fixed a production bug by adding extra "0" in
> a numeric literal in a JS code on a page.
> Since long I wish there are is a mechanism to represent Thousand
> separator in Java Script numeric literals, to make code more readable.
> 
> I see the use of underscore to do this in Ruby
> http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_stdtypes.html#S1
> Can we have a similar feature in JavaScript.
> By adding a Thousand separator in the code will reduce a great number
> of such errors.
> 
> Sample
> 123_456                   # Fixnum (underscore ignored)
> 123_456_789_123_345_789   # Bignum
> -0b101_010                # Binary (negated)
> 
> Cheers
> Biju
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
> 

-- 
Dr. Axel Rauschmayer
axel at rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120430/8a229d97/attachment-0001.html>


More information about the es-discuss mailing list