荷兰语语言逗号的Android被解释为DOT(。)
我正在使用以下代码将用户在EditText中输入的金额进行格式化。
fun String.formatWithComma(): String {
return try {
val formatter = DecimalFormat("#,###,###")
formatter.format(toDouble())
} catch (ex: Exception) {
return ""
}
}
但是,当我将电话语言切换到荷兰语时,逗号将转换为点(。)。就像用户想要键入4,323一样,将其转换为4.323。
我想甚至用荷兰语来逗号而不是点。任何解决方案
I am using the following code to format the amount entered by user in EditText.
fun String.formatWithComma(): String {
return try {
val formatter = DecimalFormat("#,###,###")
formatter.format(toDouble())
} catch (ex: Exception) {
return ""
}
}
But when I switch the phone language to dutch, the comma is converted to dot (.). Like if user wants to type 4,323 , it is converted to 4.323.
I want to comma instead of dot even in dutch language. Any solution
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一些欧洲国家的使用方式与美国和英国不同。在使用之前,您应该添加一条额外的行以指示它:
Some European countries use comma and dot in the different way than USA and England. You should add an extra line to instruct it before you use it:
我不确定是否可以解决您的问题。
如果我们在字符串中找到了多个点,我将替换值,根据您的需求改进该解决方案。
I am not sure, if this will fix your problem.
If we found multiple dots in the string, I am replacing that values, Improve this solution based on your needs.
基于 aimin pan
解决此问题的最终解决方案是
On the basis of answer given by AIMIN PAN
Final solution to fix this issue is