Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incorrect result when there is no dot in mask #5

Open
magicaner opened this issue Jan 31, 2017 · 9 comments
Open

incorrect result when there is no dot in mask #5

magicaner opened this issue Jan 31, 2017 · 9 comments

Comments

@magicaner
Copy link

for format like: #,##0 it still shows all decimals, but sohuld not.

@Mottie
Copy link
Owner

Mottie commented Jan 31, 2017

Hi @magicaner!

This is the expected result when only one symbol is supplied in the mask.

In the main readme, there is a note that better explains this behavior:

When there's only one symbol is supplied, system will always treat the single symbol as Decimal. For instance, format( '#,###', 1234567.890) will output 1234567,890. To force a single symbol as Separator, add a trailing dot to the end like this: format( '#,###.', 1234567.890) which will then output 1,234,567.

I created this demo to make testing the mask a little easier.

@Mottie
Copy link
Owner

Mottie commented Jan 31, 2017

Wow, I think I need to reword that note... I speaky betta Engrish den dat!

@magicaner
Copy link
Author

but this works differently at zend framework number formatter.
https://framework.zend.com/manual/1.11/en/zend.locale.parsing.html#zend.locale.number.localize

the following code: Zend_Locale_Format::toNumber(12.3678, array('number_format' => '#,#0.'));
will return result: 12.

what version is most correct?

@magicaner
Copy link
Author

and
the following code: Zend_Locale_Format::toNumber(12.3678, array('number_format' => '#,#0'));
will return result: 12

@Mottie
Copy link
Owner

Mottie commented Jan 31, 2017

Well, this is a very different library from the Zend framework... this one does not support normalization, localization or precision settings. So, if you are asking for "correctness" I would say go for the Zend one, they have more eyes on their code and built-in locale support.

@Mottie
Copy link
Owner

Mottie commented Jan 31, 2017

And actually, browsers have started adding a method to format & localize numbers:

var number = 123456.789;

// India uses thousands/lakh/crore separators
console.log(new Intl.NumberFormat('en-IN').format(number));
// → 1,23,456.789

// request a currency format
console.log(new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(number));
// → 123.456,79 €

// the Japanese yen doesn't use a minor unit
console.log(new Intl.NumberFormat('ja-JP', { style: 'currency', currency: 'JPY' }).format(number));
// → ¥123,457

// limit to three significant digits
console.log(new Intl.NumberFormat('en-IN', { maximumSignificantDigits: 3 }).format(number));
// → 1,23,000

@magicaner
Copy link
Author

understand. zend codes is server side, i needed client side implementation of same thing. :)
but anyway, i can use your code still, just made few modifications to make it work identically as zend implementation.

@maxkan
Copy link

maxkan commented Sep 19, 2017

I guess its a good idea to implement it exactly as in Excel. Excel-like patterns is the reason why people would consider this lib

@Mottie
Copy link
Owner

Mottie commented Sep 19, 2017

I wouldn't want to break the existing behavior. It would be better to enhance the library to include Excel-like patterns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants