Comments (3)
It seems like it doesn't work as expected (as documented) when a float is provided versus when an int is provided. Assuming it originated from .Net (which is where the culture info in Globalize originates from), it may not be intended for use with floats at all. See http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx#DFormatString "This format is supported only for integral types."
It also seems to not handle negative numbers:
Globalize.format( -1234, "d7" ) // expected: "-0001234", actual "-1234"
thought the .Net version does.
I would not except "d" to provide grouping as that is provided by "n". So if you want "1,234" or "1 234" then call format with "n" but if you want "1234", call format with "d". Or for "01234", "d5". I think you're right in that it doesn't seem that will ever be affected by a culture, as it excludes grouping and thousands and decimal (point) separators.
from globalize.
Added (failing) unit test in 47fc9e3 for negative integer with expected padding 0s after the negative sign.
from globalize.
I think this is a documentation issue. Using plain “d” is rather pointless, as with it, format() does just the job of Number.toString(). With a numeric specifier, it’s potentially useful when you need fixed-width integers left padded with zeroes (though I wonder how common the need is, except for dates and times, for which it can be done another way).
I’d suggest changing the documentation to something like the following:
• d for number in non-localized format (as per Number.toString()) padded with zeros on the left
In the prose after the bulleted list, change
“The number determines how many decimal places to display for all the format types except decimal, for which it means the minimum number of digits to display, zero padding it if necessary.”
to
“The number determines how many decimal places to display for all the format types except ‘d’, for which it means the minimum number of characters to display, zero padding it on the left if necessary.”
Oh, wait... for a negative number, we always get the result as per Number.toString(), without zero padding, apparently because the code first takes the absolute value, then creates the formatted string (possibly with leading zeros), and finally does number = -number if the value was negative. And this destroys the zero padding.
from globalize.
Related Issues (20)
- api.globalizejs.com status? HOT 1
- `"short"` date skeleton parses single-digit years HOT 1
- Unit Formatter Returning Internal Error with CLDR v40.0.0 HOT 5
- Force positive sign HOT 1
- Unit formatting megabyte in Polish short form failed because [email protected] has inconsistent data HOT 1
- Cannot get timezone names or the abbreviations from globalizer
- unitFormatter throw exception for locale "pl" with cldr-data 35 HOT 3
- Extend number format to use string instead of number HOT 4
- skeleton: "Bhm" is not supported HOT 1
- parseDate sets the time forward by an hour for non DST date time HOT 2
- Potential security issue HOT 1
- index.html
- Percent format and parsing HOT 2
- Module not found: Error: Cannot resolve module 'cldr' - in cypress tests
- Active development status check ???? HOT 1
- new Func() in globalize dist folder HOT 1
- important! How to convert date to custom format?
- Globalize date formatter prints quotes around string literals when using short formats
- Globalize date formatter prints quotes around string literals when using short formats
- Make the constructor case-insensitive HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from globalize.