glow.lang.formatNumber()
Reported by Stephen Elson | July 17th, 2009 @ 01:44 PM | in 2.0
A basic function for outputting a number as a string, such as adding zeros to the start / end (perhaps a better name could be chosen)
Eg, would take 6 and produce "06", or take .3 and produce 00.30.
The amount of padding would obviously be configurable.
Very useful when outputting dates & times.
Comments and changes to this ticket
-
Stephen Elson July 17th, 2009 @ 01:49 PM
- Milestone changed from 1.6 to 1.7
-
Stephen Elson July 18th, 2009 @ 09:53 AM
- Tag changed from enhancement to enhancement, lang
- Title changed from glow.lang.formatNumber to glow.lang.formatNumber()
-
Stephen Elson July 24th, 2009 @ 02:55 PM
- Milestone changed from 1.7 to 2.0
-
KushalP June 6th, 2010 @ 11:14 AM
Surely you're better off creating a leftPad(str, len, char) where you can define the left padding you want by a specific character and then apply it to the formatNumber() case? This was you can use it later on.
-
KushalP June 6th, 2010 @ 11:22 AM
This is my slightly inelegant implementation:
function leftPad(num, len, charIn) { var numPad = num + ''; while (numPad.length < len) { numPad = charIn + numPad; } return numPad; }
-
Jake Archibald June 7th, 2010 @ 08:30 AM
Yeah, this ticket is simply for "formatNumber", the implementation may involve creating any number of helper functions which may also be given a public API.
As you say, leftPad may be useful here, but you'd also need a similar function to operate on the right-hand side of the string, which would need to do rounding as well as padding.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
A JavaScript Library