Questions tagged [currency]

Currency is a medium of exchange of value, usually referring to government issued denominations.

The Currency tag is relevant to any topic that involves the handling of currency, including accurate calculation, rounding schemes, best practices and display formatting. It is also applicable to discussions of how specific languages or libraries handle currency.

http://en.wikipedia.org/wiki/Currency

2742 questions
2076
votes
66 answers

How to format numbers as currency strings

I would like to format a price in JavaScript. I'd like a function which takes a float as an argument and returns a string formatted like this: "$ 2,500.00" What's the best way to do this?
Daniel Magliola
  • 27,613
  • 56
  • 154
  • 235
1033
votes
16 answers

Why not use Double or Float to represent currency?

I've always been told never to represent money with double or float types, and this time I pose the question to you: why? I'm sure there is a very good reason, I simply do not know what it is.
Fran Fitzpatrick
  • 16,032
  • 15
  • 31
  • 33
930
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
  • 17,252
  • 15
  • 42
  • 49
454
votes
9 answers

What is the best data type to use for money in C#?

What is the best data type to use for money in C#?
NotDan
  • 30,143
  • 35
  • 111
  • 154
334
votes
13 answers

What is the best method of handling currency/money?

I'm working on a very basic shopping cart system. I have a table items that has a column price of type integer. I'm having trouble displaying the price value in my views for prices that include both Euros and cents. Am I missing something obvious…
Barry Gallagher
  • 5,865
  • 4
  • 24
  • 30
306
votes
12 answers

Best data type to store money values in MySQL

I want to store many records in a MySQL database. All of them contains money values. But I don't know how many digits will be inserted for each one. Which data type do I have to use for this purpose? VARCHAR or INT (or other numeric data types)?
Mohammad Saberi
  • 11,594
  • 23
  • 65
  • 123
197
votes
11 answers

What data type to use for money in Java?

What data type should you use for money in Java?
questborn
  • 2,395
  • 2
  • 13
  • 16
178
votes
10 answers

Storing money in a decimal column - what precision and scale?

I'm using a decimal column to store money values on a database, and today I was wondering what precision and scale to use. Since supposedly char columns of a fixed width are more efficient, I was thinking the same could be true for decimal columns.…
Ivan
  • 77,768
  • 15
  • 47
  • 57
176
votes
15 answers

Currency formatting in Python

I am looking to format a number like 188518982.18 to £188,518,982.18 using Python. How can I do this?
RailsSon
  • 17,439
  • 31
  • 80
  • 104
115
votes
17 answers

HTML text input field with currency symbol

I would like to have a text input field containing the "$" sign in the very beginning, and no matter what editing occurs to the field, for the sign to be persistent. I would be good if only numbers were accepted for input, but that's just a fancy…
User3419
  • 1,576
  • 2
  • 13
  • 16
113
votes
15 answers

Programmatically access currency exchange rates

I'm setting up an online ordering system but I'm in Australia and for international customers I'd like to show prices in US dollars or Euros so they don't have to make the mental effort to convert from Australian dollars. Does anyone know if I can…
Adam Pierce
  • 30,917
  • 21
  • 66
  • 86
109
votes
16 answers

Displaying the Indian currency symbol on a website

This symbol for the rupee, the currency of India, was approved by the Union Cabinet on 15 July 2010. How can I display it on a website?
JustLearn
  • 3,395
  • 10
  • 26
  • 30
108
votes
5 answers

Cast a Double Variable to Decimal

How does one cast a double to decimal which is used when doing currency development. Where does the M go? decimal dtot = (decimal)(doubleTotal);
flo
  • 1,191
  • 2
  • 10
  • 13
94
votes
14 answers

Representing Monetary Values in Java

I understand that BigDecimal is recommended best practice for representing monetary values in Java. What do you use? Is there a better library that you prefer to use instead?
dshaw
  • 2,109
  • 2
  • 14
  • 17
94
votes
21 answers

Java Currency Number format

Is there a way to format a decimal as following: 100 -> "100" 100.1 -> "100.10" If it is a round number, omit the decimal part. Otherwise format with two decimal places.
DD.
  • 19,793
  • 49
  • 140
  • 237
1
2 3
99 100