Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-31-2012, 12:34 AM   PM User | #1
friz
New Coder

 
Join Date: Oct 2007
Posts: 72
Thanks: 26
Thanked 0 Times in 0 Posts
friz is an unknown quantity at this point
Scanner nextDouble - decimal comma or point

I'm just starting with Java and the following is not quite clear to me.
I wrote this piece of very basic code and it only let's me input numbers with a decimal comma, not with a decimal point.

I thought all computer input had to be with a decimal point? Or is this because of locale settings on my pc?
(only tested in Eclips SDK)

Code:
import java.util.Scanner;
public class ingave {
	private static Scanner myScannerThree;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		myScannerThree = new Scanner(System.in);
		double amount;
		double getal;
		
		System.out.print("Give me a number: ");
		getal = myScannerThree.nextDouble();
		amount = getal + 2.95;
		
		System.out.print("You entered ");
		System.out.print(getal);
		System.out.print(". The total amount is now: ");
		System.out.println(amount);
	}

}

Last edited by friz; 10-31-2012 at 02:24 AM..
friz is offline   Reply With Quote
Old 10-31-2012, 01:05 AM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Yeppers, Scanner is locale aware, so the number format is based on your system locale.
You can change it using the scanner's useLocale(Locale) method.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
friz (10-31-2012)
Old 10-31-2012, 02:24 AM   PM User | #3
friz
New Coder

 
Join Date: Oct 2007
Posts: 72
Thanks: 26
Thanked 0 Times in 0 Posts
friz is an unknown quantity at this point
Thank you!
friz is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:31 AM.


Advertisement
Log in to turn off these ads.