decimal.js
An arbitrary-precision Decimal type for JavaScript
decimal.js API
I'd like to round up to 2 decimal places, but only if necessary.
Input:
10
1.7777777
9.1
Output:
10
1.78
9.1
How can I do this in JavaScript?
Source: (StackOverflow)
Trying to remove all letters and characters that are not 0-9 and a period. Im using Character.isDigit() but it also removes decimal, how can I also keep the decimal.
Source: (StackOverflow)
Yesterday during debugging something strange happened to me and I can't really explain it:


So maybe I am not seeing the obvious here or I misunderstood something about decimals in .NET but shouldn't the results be the same?
Source: (StackOverflow)
I have been trying to use decimal values as params for a field attribute but i get a compiler error.
I found this blog post link saying it wasn't possible in .Net to use then, does anybody know why they choose this or how can I use decimal params?
Thanks.
Source: (StackOverflow)
Simple question - why does the Decimal type define these constants? Why bother?
I'm looking for a reason why this is defined by the language, not possible uses or effects on the compiler. Why put this in there in the first place? The compiler can just as easily in-line 0m as it could Decimal.Zero, so I'm not buying it as a compiler shortcut.
Source: (StackOverflow)
I'm trying to find a fast way to remove zero decimals
from number values like this:
echo cleanNumber('125.00');
// 125
echo cleanNumber('966.70');
// 966.7
echo cleanNumber(844.011);
// 844.011
Does exists some optimized way to do that?
Source: (StackOverflow)
What is the best way to format the following number that is given to me as a String?
String number = "1000500000.574" //assume my value will always be a String
I want this to be a String with the value: 1,000,500,000.57
How can I format it as such?
Source: (StackOverflow)
I always tell in c# a variable of type double is not suitable for money. All weird things could happen. But I can't seem to create an example to demonstrate some of these issues. Can anyone provide such an example?
(edit; this post was originally tagged C#; some replies refer to specific details of decimal
, which therefore means System.Decimal
).
(edit 2: I was specific asking for some c# code, so I don't think this is language agnostic only)
Source: (StackOverflow)
I have a variable of decimal
type and I want to check the number of digits before decimal point in it.
What should I do? For example, 467.45
should return 3
.
Source: (StackOverflow)
I have some fields returned by a collection as
2.4200
2.0044
2.0000
I want results like
2.42
2.0044
2
I tried with String.Format
, but it returns 2.0000
and setting it to N0
rounds the other values as well.
Source: (StackOverflow)
What is the difference between Decimal
, Float
and Double
in .NET?
When would someone use one of these?
Source: (StackOverflow)
I'm running into a paradigm problem here. I don't know whether I should store money as a Decimal(), or if I should store it as a string and convert it to a decimal myself. My reasoning is this:
PayPal requires 2 decimal places, so if I have a product that is 49 dollars even, PayPal wants to see 49.00 come across the wire. Django's DecimalField() doesn't set a decimal amount. It only stores a maximum decimal places amount. So, if you have 49 in there, and you have the field set to 2 decimal places, it'll still store it as 49. I know that Django is basically type casting when it deserializes back from the database into a Decimal (since Databases don't have decimal fields), so I'm not completely concerned with the speed issues as much as I am with the design issues of this problem. I want to do what's best for extensibility.
Or, better yet, does anyone know how to configure a django DecimalField() to always format with the TWO_PLACES formatting style.
Source: (StackOverflow)
In the interest of creating cross-platform code, I'd like to develop a simple financial application in JavaScript. The calculations required involve compound interest and relatively long decimal numbers. I'd like to know what mistakes to avoid when using JavaScript to do this type of math—if it is possible at all!
Source: (StackOverflow)