change comma to point

0 Deniss Diks · March 23, 2015
in eclipse I can enter double numbers only with comma, such like 2,67, if I do that with point then comes "at java.util.Scanner.nextDouble(Unknown Source)"! how to change "," to "." ?

Post a Reply

Replies

Oldest  Newest  Rating
0 Milan Obrenovic · March 23, 2015
Try using the if statement. Check whether the user has entered a comma (,) and if so, swap the value at the found index with a dot (.) instead of a comma.
+1 Nicholas Eason · March 23, 2015
//Scanner initialization stuff

Double yourNumber = in.nextDouble();
String num = yourNumber.toString();
if(num.contains(",")){
num.replace(",",".");
Double newNumber = Double.parseDouble(num);
}
  • 1

Java / Android Development

107,058 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator