new Intl.NumberFormat("en", {round: "floor"});If you have any thoughts, they are welcome:
let formatUsingFloorRounding = new Intl.NumberFormat("en").format(Math.floor(Math.PI)); // "3.141" let formatCurrencyUsingCeilRounding = new Intl.NumberFormat("en", { style: "currency", currency: "USD", currencyDisplay: "symbol" }).format(Math.ceil(9.991)); // or Math.trunc() or Math.round(), etc... // "$10.00"
--
You received this message because you are subscribed to the Google Groups "JavaScript Globalization" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javascript-globali...@googlegroups.com.
To post to this group, send email to javascript-g...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/javascript-globalization/CADdLYspzsTrthWEqXcHzBL%2BibBKHU-h1YFsSvUfCs1HRnX_58A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
1. how will the output vary for other locales? it seems that this is only applicable for smallest currency denotation in some locales. I’m worry about introducing a formatting option that might affect the way currency is visualized while the internals of the program will be using a different numeric value. E.g.: what if we format the total amount to be charged in a paypal form, and it says $10, while in reality we will charge 10.4 once we redirect to paypal. It seems to me that any operation with number belongs to the numbers realm in the business logic of the program. e.g.:
let currencyFormattingOption = {style:"currency", currency: "USD", currencyDisplay: "symbol"}; new Intl.NumberFormat("en", currencyFormattingOption).format(9); // "$9.00" new Intl.NumberFormat("en", currencyFormattingOption).format(9); // "¥9"
2. what will be the symmetry of this with the reflective Math api? I’m concern that the behavior of this formatting process might diverge from the Reflective `Math` 262 specification (I don’t know the details of the implementation though).
3. do other languages support this formatting rules for numbers? java? php? this is something we should analyze and document as part of the proposal.
Other logistics: I don’t think we should allocate this in stage 0 just yet, let’s just call it a proposal, and if the commite decides that we can process with it, then we set it to stage 0.
new Intl.NumberFormat("en", {style:"currency", currency: "JPY", currencyDisplay: "symbol"}).format(9); // "¥9"
Hi Caridy,Thanks for your questions.1. how will the output vary for other locales? it seems that this is only applicable for smallest currency denotation in some locales. I’m worry about introducing a formatting option that might affect the way currency is visualized while the internals of the program will be using a different numeric value. E.g.: what if we format the total amount to be charged in a paypal form, and it says $10, while in reality we will charge 10.4 once we redirect to paypal. It seems to me that any operation with number belongs to the numbers realm in the business logic of the program. e.g.:Please, could you clarify? I'm confused, because: numbers/currencies are always rounded whether or not you specify the rounding method. It always uses the half-even round. Are you suggesting this behavior will always cause problems for applications and instead applications should always round the numbers themselves before using the formatter?
Math.round(), Math.floor(), Math.ceil(), etc do not round to a given decimal digit, only to integers, I'm assuming this has been used this way here as a simplified demonstration. Considering the application knows in advance which decimal place the round is going to take place and rounds the number as you suggest, should we enforce that usage? It's a lot of duplicate work: (b.i) if no options have been used, maximumFractionDigits defaults to 3, so in theory the application could round-in-advance numbers to the 3rd decimal place using a special rounding function that takes the decimal digit in for rounding, (b.ii) if minimumSignificantDigits and maximumSignificantDigits have been used, the formatter will round the number at a different decimal case depending of each value, so in theory the application could round-in-advance numbers using a special rounding function that takes the value and significant min and max values in for rounding. It seems to me a lot of work if the application simply wants to display the number rounded using its preferred method.
It's not always possible to know the decimal place in advance, currencies as an example (as you've mentioned). Note, it's not locale dependent. But, currency dependent.let currencyFormattingOption = {style:"currency", currency: "USD", currencyDisplay: "symbol"}; new Intl.NumberFormat("en", currencyFormattingOption).format(9); // "$9.00" new Intl.NumberFormat("en", currencyFormattingOption).format(9); // "¥9"Your paypal example is a perfect demonstration where formatting should use ceil instead of the default rounding. If it had shown $11 and charged $10.4, customer would be happy. :D Or more realistically, displaying $10.01, when value is $10.004 and have the backend to charge for the same displayed $10.01 would be fine. I want to emphasize that not necessarily the paypal example will have problems because of whether or not the number has been rounding in advance of the formatter on the client side. But, it will have a problem if the application is not well architected. Let me clarify, in this case the problem happens if it performs two different actions on the client vs. on the server.2. what will be the symmetry of this with the reflective Math api? I’m concern that the behavior of this formatting process might diverge from the Reflective `Math` 262 specification (I don’t know the details of the implementation though).I have no idea either. Perhaps Rick could weigh in.
EDIT:new Intl.NumberFormat("en", {style:"currency", currency: "JPY", currencyDisplay: "symbol"}).format(9); // "¥9"
Hi Caridy,Thanks for your questions.1. how will the output vary for other locales? it seems that this is only applicable for smallest currency denotation in some locales. I’m worry about introducing a formatting option that might affect the way currency is visualized while the internals of the program will be using a different numeric value. E.g.: what if we format the total amount to be charged in a paypal form, and it says $10, while in reality we will charge 10.4 once we redirect to paypal. It seems to me that any operation with number belongs to the numbers realm in the business logic of the program. e.g.:Please, could you clarify? I'm confused, because: numbers/currencies are always rounded whether or not you specify the rounding method. It always uses the half-even round. Are you suggesting this behavior will always cause problems for applications and instead applications should always round the numbers themselves before using the formatter?
Math.round(), Math.floor(), Math.ceil(), etc do not round to a given decimal digit, only to integers, I'm assuming this has been used this way here as a simplified demonstration. Considering the application knows in advance which decimal place the round is going to take place and rounds the number as you suggest, should we enforce that usage? It's a lot of duplicate work: (b.i) if no options have been used, maximumFractionDigits defaults to 3, so in theory the application could round-in-advance numbers to the 3rd decimal place using a special rounding function that takes the decimal digit in for rounding, (b.ii) if minimumSignificantDigits and maximumSignificantDigits have been used, the formatter will round the number at a different decimal case depending of each value, so in theory the application could round-in-advance numbers using a special rounding function that takes the value and significant min and max values in for rounding. It seems to me a lot of work if the application simply wants to display the number rounded using its preferred method.
It's not always possible to know the decimal place in advance, currencies as an example (as you've mentioned). Note, it's not locale dependent. But, currency dependent.let currencyFormattingOption = {style:"currency", currency: "USD", currencyDisplay: "symbol"}; new Intl.NumberFormat("en", currencyFormattingOption).format(9); // "$9.00" new Intl.NumberFormat("en", currencyFormattingOption).format(9); // "¥9"Your paypal example is a perfect demonstration where formatting should use ceil instead of the default rounding. If it had shown $11 and charged $10.4, customer would be happy. :D Or more realistically, displaying $10.01, when value is $10.004 and have the backend to charge for the same displayed $10.01 would be fine. I want to emphasize that not necessarily the paypal example will have problems because of whether or not the number has been rounding in advance of the formatter on the client side. But, it will have a problem if the application is not well architected. Let me clarify, in this case the problem happens if it performs two different actions on the client vs. on the server.Sure, I'm ok with whatever name. On https://github.com/tc39/ecma402 table, there's a stage column. I'm using 0 there, because it will only be inserted if the PR is accepted and merged.2. what will be the symmetry of this with the reflective Math api? I’m concern that the behavior of this formatting process might diverge from the Reflective `Math` 262 specification (I don’t know the details of the implementation though).I have no idea either. Perhaps Rick could weigh in.3. do other languages support this formatting rules for numbers? java? php? this is something we should analyze and document as part of the proposal.I know Unicode Technical Standard #35 (UTS#35) clearly suggests a rounding option: "An implementation may allow the specification of a rounding mode to determine how values are rounded" here.Steven, does ICU allow that?
I will reply if I find out how this work for other programming languages.Other logistics: I don’t think we should allocate this in stage 0 just yet, let’s just call it a proposal, and if the commite decides that we can process with it, then we set it to stage 0.
Rick
--
You received this message because you are subscribed to the Google Groups "JavaScript Globalization" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javascript-globali...@googlegroups.com.
To post to this group, send email to javascript-g...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/javascript-globalization/CAHfnhfqfAtgVBy8gDvdZms%3Dh_8Uuywx5Lz%2BMfDhZ45zb05Lkcw%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "JavaScript Globalization" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javascript-globali...@googlegroups.com.
To post to this group, send email to javascript-g...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/javascript-globalization/00ba28b8-ed6e-4f10-9cc3-971549366e23%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/javascript-globalization/605EC2CF-31B6-41D0-9BE4-BFDA10438FEE%40gmail.com.