Comments (3)
I'm not understanding what you expect to happen here - when I run either line from a normal JVM (i.e. not GWT), I get an exception (tested in Java 11 and 21, line numbers below from 11):
Exception java.lang.ArithmeticException: Rounding necessary
at BigDecimal.commonNeedIncrement (BigDecimal.java:4653)
at BigDecimal.needIncrement (BigDecimal.java:4860)
at BigDecimal.divideAndRound (BigDecimal.java:4835)
at BigDecimal.setScale (BigDecimal.java:2923)
at BigDecimal.setScale (BigDecimal.java:2838)
Are you sure that this should work as you have it written? Or are you saying that GWT incorrectly does not throw an exception here (though GWT's behavior appears to the same at a brief glance...)?
from gwt.
Well that's how Java has defined BigDecimal
. If you want to reduce the scale you have to tell BigDecimal
how to round the number in order to fit into the new scale.
Reducing the scale using RoundingMode.UNNECESSARY
can only be successful if your BigDecimal
has enough zeros at the end. If you want to truncate your BigDecimal
to a given scale you should use RoundingMode.DOWN/FLOOR
.
Also in your example you have used the constructor BigDecimal(double)
which is kind of a beast as there are many double values that cannot be represented exactly in binary form. Given your example number 91.0202
one might think the scale is 4 but in reality it is 46 because 91.0202
cannot be represented exactly. The binary form of that number represents 91.0202000000000026602720026858150959014892578125
.
So it is advisable to use the constructor BigDecimal(String)
instead.
Using the string based constructor something like below will work:
new BigDecimal("92.0200").setScale(2, RoundingMode.UNNECESSARY);
new BigDecimal("92.0200").setScale(2);
It works because the number has two zeros at the end and thus fits into a scale of 2 without any rounding.
from gwt.
Closing the issue because the exception is expected based on the provided example.
from gwt.
Related Issues (20)
- StackTraceDeobfuscator sometimes produces total nonsense HOT 5
- Regression in jsinterop varargs causing internal compiler error HOT 3
- Tutorial: webAppCreator deprecated but necessary for tutorials HOT 2
- Need a method to run DevMode on systems without GUI support HOT 1
- SuperDevListener is not correctly build includeJsInteropExports/excludeJsInteropExports args
- Issue with tomcat version of GWT 2.11 for class javax.validation.Path HOT 8
- JDK 17 and GIN HOT 16
- SDM BindException: Address already in use
- GWT compiling issue in java 11 HOT 2
- Spurious incremental CompilerTest failure
- GWT 2.11 and Jetty 9.4.54.v20240208 error running in IntelliJ 2024.1 Ultimate HOT 2
- SDM (Super Dev Mode) does not work with a strong CSP (Content Security Policy)
- Draft compile with compiler.stackMode=strip seems to break stack trace deobfuscation with sourcemaps HOT 1
- Upgrade to HtmlUnit 3.9.0 or 4.1.0 HOT 2
- Upgrade icu4j to a version > 63.1
- Memory leak in stored exceptions HOT 7
- Issue with com.google.gwt.i18n.client.TimeZone in GWT 2.11 for Africa/Cairo Time Zone HOT 4
- Add Java 9 BigInteger methods sqrt and sqrtAndRemainder
- GWT from 2.9 to 2.11 Migration Issue Could not find com.google.gwt:gwt-codeserver:2.11.0. HOT 1
- Remove onLoadErrorFn/onPropertyErrorFn, or make them easier to disable
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 gwt.