Questions tagged [decimal]

Decimal is the name for our common base-ten numeral system. It may also refer to non-integer values expressed with a decimal point.

Decimal is the base-10 positional numeral system. It is the ordinary numeral system we use; it can be used to represent both integers and (using a decimal point) non-integer values.

Related tags

7532 questions
2419
votes
18 answers

Difference between decimal, float and double in .NET?

What is the difference between decimal, float and double in .NET? When would someone use one of these?
Tom
1458
votes
39 answers

How to round a number to n decimal places in Java

What I would like is a method to convert a double to a string which rounds using the half-up method - i.e. if the decimal to be rounded is 5, it always rounds up to the next number. This is the standard method of rounding most people expect in most…
Alex Spurling
  • 54,094
  • 23
  • 70
  • 76
997
votes
7 answers

decimal vs double! - Which one should I use and when?

I keep seeing people using doubles in C#. I know I read somewhere that doubles sometimes lose precision. My question is when should a use a double and when should I use a decimal type? Which type is suitable for money computations? (ie. greater…
Soni Ali
  • 18,464
  • 16
  • 44
  • 53
815
votes
19 answers

How do I display a decimal value to 2 decimal places?

When displaying the value of a decimal currently with .ToString(), it's accurate to like 15 decimal places, and since I'm using it to represent dollars and cents, I only want the output to be 2 decimal places. Do I use a variation of .ToString()…
wows
  • 10,687
  • 7
  • 27
  • 27
800
votes
13 answers

How to convert Decimal to Double in C#?

I want to assign the decimal variable "trans" to the double variable "this.Opacity". decimal trans = trackBar1.Value / 5000; this.Opacity = trans; When I build the app it gives the following error: Cannot implicitly convert type decimal to double
Eggs McLaren
  • 1,777
  • 3
  • 12
  • 13
486
votes
16 answers

How do you round a number to two decimal places in C#?

I want to do this using the Math.Round function
Laila
442
votes
5 answers

What does the M stand for in C# Decimal literal notation?

In order to work with decimal data types, I have to do this with variable initialization: decimal aValue = 50.0M; What does the M part stand for?
coson
  • 8,301
  • 15
  • 59
  • 84
354
votes
32 answers

Get decimal portion of a number with JavaScript

I have float numbers like 3.2 and 1.6. I need to separate the number into the integer and decimal part. For example, a value of 3.2 would be split into two numbers, i.e. 3 and 0.2 Getting the integer portion is easy: n = Math.floor(n); But I am…
Oscar
  • 3,551
  • 2
  • 15
  • 5
341
votes
24 answers

Python JSON serialize a Decimal object

I have a Decimal('3.9') as part of an object, and wish to encode this to a JSON string which should look like {'x': 3.9}. I don't care about precision on the client side, so a float is fine. Is there a good way to serialize this? JSONDecoder doesn't…
Knio
  • 6,638
  • 3
  • 29
  • 29
336
votes
14 answers

How can I remove the decimal part from JavaScript number?

I have the results of a division and I wish to discard the decimal portion of the resultant number. How can I do this?
JacobTheDev
  • 17,318
  • 25
  • 95
  • 158
316
votes
3 answers

Float vs Decimal in ActiveRecord

Sometimes, Activerecord data types confuse me. Err, often. One of my eternal questions is, for a given case, Should I use :decimal or :float? I've often come across this link, ActiveRecord: :decimal vs :float?, but the answers aren't quite clear…
300
votes
4 answers

How do I interpret precision and scale of a number in a database?

I have the following column specified in a database: decimal(5,2) How does one interpret this? According to the properties on the column as viewed in SQL Server Management studio I can see that it means: decimal(Numeric precision, Numeric…
mezoid
  • 28,090
  • 37
  • 107
  • 148
298
votes
11 answers

Java String remove all non numeric characters but keep the decimal separator

Trying to remove all letters and characters that are not 0-9 and a period. I'm using Character.isDigit() but it also removes decimal, how can I also keep the decimal?
DRing
  • 6,825
  • 6
  • 29
  • 45
296
votes
8 answers

How to store decimal values in SQL Server?

I'm trying to figure out decimal data type of a column in the SQL Server. I need to be able to store values like 15.5, 26.9, 24.7, 9.8, etc I assigned decimal(18, 0) to the column data type but this not allowing me to store these values. What is…
Alex
  • 39,265
  • 21
  • 45
  • 42
296
votes
12 answers

When should I use double instead of decimal?

I can name three advantages to using double (or float) instead of decimal: Uses less memory. Faster because floating point math operations are natively supported by processors. Can represent a larger range of numbers. But these advantages seem to…
Jamie Ide
  • 48,427
  • 16
  • 81
  • 117
1
2 3
99 100