2009-01-22 51 views
1

如何從GWT獲取用戶本地小數點分隔符字符。我找到了NumberFormat工具,它只返回整個格式並提供解析。GWT獲取用戶本地小數點分隔符char

NumberFormat.getDecimalFormat()... 

是否有一種(簡單的)方法從十進制格式獲取小數點分隔符,千位分隔符。

回答

1

您可以使用已知的數字對它進行種子處理,然後對其進行解析以獲得所需的字符。

import com.google.gwt.i18n.client.NumberFormat; 

NumberFormat fmt = NumberFormat.getDecimalFormat(); 
double value = 1234.5; 
String formatted = fmt.format(value); 
String thousandSeparator = formatted.substring(1,2); 
String decimalSeparator = formatted.substring(5,6); 
+0

這也是我的想法,但我認爲還有一個更優雅的方式來做到這一點。將這個標記爲正確的答案,因爲在2天內這是唯一的答案。 – Drejc 2009-01-25 20:04:34

13
import com.google.gwt.i18n.client.LocaleInfo; 

String decimalSeparator = LocaleInfo.getCurrentLocale().getNumberConstants().decimalSeparator(); 
String thousandSeparator = LocaleInfo.getCurrentLocale().getNumberConstants().groupingSeparator(); 
+1

工程就像一個魅力 – 2013-03-27 13:55:21