Java 使用小数点的句点,例如1/2 = 0.5
有没有办法让它使用逗号代替,如 1/2 = 0,5?并且不要使用逗号来表示千(例如十万= 100,000)而是使用空格(100 000)?
当谈到输出时,我想我可以使用各种字符串格式函数,但问题是输入(JTable)。有些列需要 Double 格式,因此用户必须输入类似 45.5 的内容,在这些部分中,他们习惯了 45,5 :) 提前致谢
Update:
我尝试使用 myTable.setDefaultLocale(Locale.Germany);但它不起作用。我还做了 Locale.setDefault(Locale.Germany); @ main 函数,它确实有效,但以相当愚蠢的方式:当单元格处于编辑模式时,您必须正常输入点,即 45.5 但after您按 Enter 确认更改,它显示为逗号:45,5。我的意思是它仅使用逗号用于显示目的,但在编辑其仍然相同的点时。
有什么办法可以解决吗without编写自定义表模型?
看一眼针对区域设置格式化和解析数字 http://www.exampledepot.com/egs/java.text/Numbers.html:
// Format for CANADA locale
Locale locale = Locale.CANADA;
String string = NumberFormat.getNumberInstance(locale).format(-1234.56); // -1,234.56
// Format for GERMAN locale
locale = Locale.GERMAN;
string = NumberFormat.getNumberInstance(locale).format(-1234.56); // -1.234,56
// Format for the default locale
string = NumberFormat.getNumberInstance().format(-1234.56);
// Parse a GERMAN number
try {
Number number = NumberFormat.getNumberInstance(locale.GERMAN).parse("-1.234,56");
if (number instanceof Long) {
// Long value
} else {
// Double value
}
} catch (ParseException e) {
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)