question

woolton-dev avatar image
woolton-dev asked woolton-dev commented

Why are some fields "long" instead of double/decimal?

We found that some fields are a 64 bit integer instead of a floating point. Is this a mistake? We're still in the process of mapping fields, so we have not gotten to view actual data yet. For example Payments has a field amount and also Orders has a field total. Both of these are a "long". In JAVA it's mapped as a java.lang.Long. What are we missing here? Is it just a mistake?

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jacob Abrams avatar image
Jacob Abrams answered woolton-dev commented

It is not a mistake, the values are longs that represent cents. Floating point numbers aren't a good choice when storing monetary values, take a look at http://stackoverflow.com/questions/37... for more information.

1 comment
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

woolton-dev avatar image woolton-dev commented ·

Got it! Makes sense. We were thinking something like this, but we weren't sure if this was the case. Thanks again for your response.

0 Likes 0 ·
johnsonjeven avatar image
johnsonjeven answered

Precision is the main difference where double is a double precision (64 bit) floating point data type and decimal is a 128-bit floating point data type.

Double - 64 bit (15-16 digits) Decimal - 128 bit (28-29 significant digits)

So Decimals have much higher precision and are usually used within monetary (financial) applications that require a high degree of accuracy. But in performance wise Decimals are slower than double and float types. Double Types are probably the most normally used data type for real values, except handling money. More about.....Decimal vs Double vs Float

Johnson

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community