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

fixes formatting and parsing of numbers #396

Open
wants to merge 4 commits into
base: cc
Choose a base branch
from

Conversation

andekande
Copy link
Contributor

  • negative numbers were not detected
  • String.format is non existent
  • considers culture settings on Number parsing (here in germany 9,41 should not be parsed to 9)
  • exponential formatting was missing culture awareness

@@ -47,6 +47,12 @@ function parseNumber(s) {
if (!s || !s.length) {
return 0;
}

if (ss.culture.current.nf.gs.length)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parse functions aren't yet setup for globalization (unlike the format functions). The intent here was to only parse per the invariant/neutral culture.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was thinking to introduce a parseNumber(culture, s) but as you said, would be inconsistent to parseDate where culture awarenes is much more challenging. Nevertheless when coming from .Net one expects parsing to be culture aware, which in case of Numbers is easy to achieve. So I thought I would implement a robust way in the framework, rather to writing my own convert logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, I overcame a situation where forcibly parsing with currentCulture is not desireable:
jQuery.Select("#ID").GetCSS("font-size") => may return "22.5pt"
With my addition parseNumber("22.5pt") gets 225.
So I'll better keep my own version of culture aware parsing in my utils.

Jan Hesse added 3 commits May 9, 2014 11:28
short version of:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round

eg: rounding of 1.0005 with precision of 3 is different in IE than in
Chrome

string res = string.Format(CultureInfo.CurrentCulture, "{0:3}", 1.0005);
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

Successfully merging this pull request may close these issues.

2 participants