jpcsupplies / Economy_mod

Basic Economy System for Space Engineers
13 stars 12 forks source link

Double versus Decimal. #15

Closed midspace closed 9 years ago

midspace commented 9 years ago

In the project notes, the following is mentioned in regards to precision of the currency.

Units should be in decimal places. Variables to 8 decimal places.

Then converted - 1 unit of currency = for example 0.00000100 Used in game would be shown as 1.00 So 1 whole real unit would be equal to 1,000,000.00 in game (or 1.00000000

https://github.com/jpcsupplies/Economy_mod/wiki/8.-General-notes-to-self

Double, is a floating point number, is and as such, is subject to inaccuracies over large amounts of decimal places, and it's primary purpose is speed when doing many calculations.

Decimal while a little slower, maintains precision and it's purpose is currency.

http://stackoverflow.com/questions/1165761/decimal-vs-double-which-one-should-i-use-and-when http://stackoverflow.com/questions/618535/difference-between-decimal-float-and-double-in-net

Current code where Double has been defined for holding currency, and conversion of values from string, need to be changed to Decimal.

jpcsupplies commented 9 years ago

moving to decimals from doubles, good catch, doubles was just me being lazy - and i didnt think we needed that many decimal places.. (isnt a decimal just a long anyway, with an internal divide by mechanism making it transparent to the user..)