Comments (2)
Hi,
Doing the same thing also throws in java. It is because precision is 0. As I know, 0 precision means unlimited precision and means give me the exact result. So, we are asking the exact result from this operation but the exact result cannot be obtained with a non-terminating decimal expansion(0.3333...).
This code
new BigDecimal("1").divide(new BigDecimal("3"), new MathContext(0, RoundingMode.CEILING));
throws
Exception in thread "main" java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.
at java.math.BigDecimal.divide(BigDecimal.java:1693)
at java.math.BigDecimal.divide(BigDecimal.java:1726)
at Main.main(Main.java:23)
You can do this:
Big(1).divide(Big(3), undefined, RoundingMode.CEILING).numberValue()
// 1
which is equiavalent of Java's:
new BigDecimal(1).divide(new BigDecimal(3), RoundingMode.CEILING).intValue()
// 1
from bigdecimal.js.
Closing because I think my reply solves your problem, reopen the issue if it does not.
from bigdecimal.js.
Related Issues (9)
- ES Modules HOT 2
- No identifiers allowed directly after numeric literal HOT 13
- Add markdown link checker to avoid broken links HOT 4
- Fix doc
- Extends API to support compareTo aliases (===, >, >=, etc...) HOT 5
- Make `add`, `subtract`, `multiply`, `divide` & `compareTo` handle `any` HOT 2
- Create a bigdecimal-light.js HOT 4
- "Can't find variable: BigInt" error thrown on Safari 13 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bigdecimal.js.