Limit a double to two decimal places without trailing zeros
Try adding the following line, when configuring your formatter: [doubleValueWithMaxTwoDecimalPlaces setMaximumFractionDigits:2];
Try adding the following line, when configuring your formatter: [doubleValueWithMaxTwoDecimalPlaces setMaximumFractionDigits:2];
If you don’t care about the commas, then floatformat will do the job: {{ value|floatformat:”0″ }} If you do care about commas, you want: {{ value|floatformat:”0″|intcomma }} (Hat tip to Stephen for pointing me at intcomma!)
The precision is fixed, which is exactly 53 binary digits for double-precision (or 52 if we exclude the implicit leading 1). This comes out to about 15 decimal digits. The OP asked me to elaborate on why having exactly 53 binary digits means “about” 15 decimal digits. To understand this intuitively, let’s consider a less-precise … Read more
Try the following expression: ^\d+\.\d{0,2}$ If you want the decimal places to be optional, you can use the following: ^\d+(\.\d{1,2})?$ EDIT: To test a string match in Javascript use the following snippet: var regexp = /^\d+\.\d{0,2}$/; // returns true regexp.test(‘10.5’)
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
.toFixed() is best solution.It will keep only two digits after dot. Exp 1: var value = 3.666; value.toFixed(2); //Output : 3.67 Exp 2: var value = 3.0000; value.toFixed(2); //Output : 3.00
You can call int() on the end result: >>> int(2.0) 2
Fluent nHibernate maps System.Decimal as decimal(19, 5)
The classes from the Decimal TR are not implemented for all compilers. Some compilers, e.g., gcc, implement the C Decimal TR and provide the corresponding extensions in C++, too. In the past there was an open source implementation for the C++ Decimal TR available but I failed to locate it. If your compiler doesn’t support … Read more