What data type should you use if you want to store the dollar amount of a transaction?

What data type should you use if you want to store the dollar amount of a transaction?

9 Answers. Something like Decimal(19,4) usually works pretty well in most cases. You can adjust the scale and precision to fit the needs of the numbers you need to store.

How do you use Currency data type?

The type-declaration character for Currency is the at (@) sign. The Currency data type is useful for calculations involving money and for fixed-point calculations in which accuracy is particularly important.

Why is double money bad?

The float and double types are particularly ill-suited for monetary calculations because it is impossible to represent 0.1 (or any other negative power of ten) as a float or double exactly. For example, suppose you have $1.03 and you spend 42c. How much money do you have left? System.

Which is the best data type for money?

BigDecimal is the best type for representing currency decimal values. Joda Money has provided a library to represent money. You can use Money and Currency API (JSR 354).

What is data type to use for money in Java?

Java has Currency class that represents the ISO 4217 currency codes. BigDecimal is the best type for representing currency decimal values. Joda Money has provided a library to represent money. You can use Money and Currency API (JSR 354). You can use this API in, provided you add appropriate dependencies to your project.

Which is datatype should be used for currency?

Numeric with forced 2 units precision. Never use float or float like datatype to represent currency because if you do, people are going to be unhappy when the financial report’s bottom line figure is incorrect by + or – a few dollars. The money type is just left in for historical reasons as far as I can tell. Your source is in no way official.

How is in game currency used in games?

Most of us have encountered in-game currency in games such as Pokémon Go or Candy Crush. Users can buy new pokéballs, extra lives or spend it on skipping a tough level. Lately in-game currency has expanded to computer and video games as well. The in-game currency is so popular that it represents almost 50% of the gaming industry’s revenue.