GWT - DoubleBox with more than 3 decimal places

2020-04-08 12:37发布

问题:

I'm creating an user interface using GWT and there're many boxes of double values but when I set some variable which contains more than 3 decimal places my DoubleBox doesn't accept and truncates the number letting just 3 places.

Is it normal?

What's the best solution?

Thank you.

回答1:

As the javadoc says DoubleBox is a ValueBox using a DoubleParser and DoubleRenderer. Those rely on NumberFormat.getDecimalFormat() which will trunk at 3 decimals in most (if not all) locales (for the default locale: http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/src/com/google/gwt/i18n/client/constants/NumberConstantsImpl.properties)

If you want another format, then use a ValueBox with a NumberFormatRenderer with your custom NumberFormat pattern (and either use the DoubleParser or make your own Parser with your custom NumberFormat pattern)