Is there a reliable way in JavaScript to obtain the number of decimal places of an arbitrary number?

Historical note: the comment thread below may refer to first and second implementations. I swapped the order in September 2017 since leading with a buggy implementation caused confusion. If you want something that maps “0.1e-100” to 101, then you can try something like function decimalPlaces(n) { // Make sure it is a number and use … Read more

Set decimal separator when using f:convertNumber

The default decimal separator depends on the locale used. You can set it in 2 ways: On a per-view basis by the locale attribute of the <f:view> tag: <f:view locale=”#{bean.locale}”> On a per-converter basis by the locale attribute of the <f:convertNumber> tag: <f:convertNumber locale=”#{bean.locale}” /> It’s unclear what locale you’re targeting, but the use of … Read more

Culture invariant Decimal.TryParse()

In fact CultureInfo.InvariantCulture can be used here. The parameter expects IFormatProvider, an interface that CultureInfo implements. But InvariantCulture is invariant in the sense that it does not vary with the user’s settings. In fact, there is no culture that accepts either , or . as decimal separator – they are all one or the other. … Read more