## 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

Categories c++

## how can i show an irrational number to 100 decimal places in python?

decimal module comes in handy. >>> from decimal import * >>> getcontext().prec = 100 >>> Decimal(2).sqrt() Decimal(‘1.414213562373095048801688724209698078569671875376948073176679737990732478462107038850387534327641573’)

## 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

## Leave only two decimal places after the dot

string.Format is your friend. String.Format(“{0:0.00}”, 123.4567); // “123.46”

## Change decimal separator in MySQL

Tip for CSV exports: SELECT REPLACE(CAST(prijs_incl AS CHAR), ‘.’, ‘,’) will give you input that can be used as numeric fields in european excelsheets.

## 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

## Convert decimal mark when reading numbers as input

You may do it the locale-aware way: import locale # Set to users preferred locale: locale.setlocale(locale.LC_ALL, ”) # Or a specific locale: locale.setlocale(locale.LC_NUMERIC, “en_DK.UTF-8”) print locale.atof(“3,14”) Read this section before using this method.

## Javascript: formatting a rounded number to N decimals

I think that there is a more simple approach to all given here, and is the method Number.toFixed() already implemented in JavaScript. simply write: var myNumber = 2; myNumber.toFixed(2); //returns “2.00” myNumber.toFixed(1); //returns “2.0” etc…