How can I set the decimal separator to be a comma?

You should use basic_ios::imbue to set the preferred locale. Take a look here: http://www.cplusplus.com/reference/ios/ios_base/imbue/ Locales allow you to use the preferred way by the user, so if a computer in Italy uses comma to separate decimal digits, in the US the dot is still used. Using locales is a Good Practice. But if you want … Read more

What is the decimal separator symbol in JavaScript?

According to the specification, a DecimalLiteral is defined as: DecimalLiteral :: DecimalIntegerLiteral . DecimalDigitsopt ExponentPartopt . DecimalDigits ExponentPartopt DecimalIntegerLiteral ExponentPartopt and for satisfying the parseFloat argument: Let inputString be ToString(string). Let trimmedString be a substring of inputString consisting of the leftmost character that is not a StrWhiteSpaceChar and all characters to the right of that … Read more

In jQuery, what’s the best way of formatting a number to 2 decimal places?

If you’re doing this to several fields, or doing it quite often, then perhaps a plugin is the answer. Here’s the beginnings of a jQuery plugin that formats the value of a field to two decimal places. It is triggered by the onchange event of the field. You may want something different. <script type=”text/javascript”> // … Read more

Integer.valueOf() vs. Integer.parseInt() [duplicate]

Actually, valueOf uses parseInt internally. The difference is parseInt returns an int primitive while valueOf returns an Integer object. Consider from the Integer.class source: public static int parseInt(String s) throws NumberFormatException { return parseInt(s, 10); } public static Integer valueOf(String s, int radix) throws NumberFormatException { return Integer.valueOf(parseInt(s, radix)); } public static Integer valueOf(String s) … Read more

Decimal separator comma (‘,’) with numberDecimal inputType in EditText

A workaround (until Google fix this bug) is to use an EditText with android:inputType=”numberDecimal” and android:digits=”0123456789.,”. Then add a TextChangedListener to the EditText with the following afterTextChanged: public void afterTextChanged(Editable s) { double doubleValue = 0; if (s != null) { try { doubleValue = Double.parseDouble(s.toString().replace(‘,’, ‘.’)); } catch (NumberFormatException e) { //Error } } … Read more