Java : How to count the number of decimals contained in a double value that represent money?
- 阅读更多 关于 Java : How to count the number of decimals contained in a double value that represent money?
问题 For a change-making application, made with Java, I am facing a problem while counting the number of decimals in a double value. The double value represent money, so all my operations must be made in consequences that a double value like 12.58 can be stored as 12.5797886 after an operation is made on the original value. To counter this effect, I chose to use String, just like this : String amountString = String.valueOf(amount); String decimals = amountString.substring(amountString.indexOf('.')