如何指定十进制分隔符 [英] How to specify decimal delimiter
本文介绍了如何指定十进制分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
6.03
,但这给我错误。如果我将其更改为 6,03
,没关系。但是,我不能更改我需要处理的输入,所以我如何告诉Java使用。
作为分隔符而不是,
? Scanner sc = new Scanner(System.in);
double gX = sc.nextDouble(); //获取错误
感谢
解决方案
扫描器
可以提供 Locale
使用,您需要指定 Locale
使用。
作为小数分隔符:
Scanner sc = new Scanner(System.in).useLocale(Locale.ENGLISH);
I have a fairly simple problem. I am getting real-number input like6.03
, but that gives me errors. If I change it to 6,03
, it's ok. I, however, can't change the input I need to process, so how do I tell Java to use .
as the delimiter instead of ,
?
Scanner sc = new Scanner(System.in);
double gX = sc.nextDouble(); // Getting errors
Thanks
解决方案
Scanner
can be provided with Locale
to use, you need to specify Locale
that uses .
as decimal separator:
Scanner sc = new Scanner(System.in).useLocale(Locale.ENGLISH);
这篇关于如何指定十进制分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文