java - Correctly divide a double to be able to get back the correct amount -


i have input method represents amount of money, total price of x items.
can amount under number of currencies , represented double.
question: want break amount price each of x items. considering amount double concern if do: amount/x number number*x not give me amount due e.g. rounding. how can correctly?
note: please give me taking granted can not change amount other double

as mentioned, not possible in every case. usually, when total price product of single item price , quantity, resulting double have enough precision calculation. have store both prices.

i implemented whole erp, , have feature user can specify total line amount directly, maybe round sum after discussing customer. , makes possible sell 7 items 1000$. there no way create precise representation of price single item. , therefore store item price rounded (cut after 4 digits).

to come answer: depending on context need total , single item amount later anyway, store both.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -