In Java, sc.useLocale(locale) tells the scanner which regional rules to use when parsing numbers, and returns the Scanner itself so calls can be chained.
It switches decimal marks (dot vs comma) and thousands grouping characters: for example, Locale.GERMANY turns "3,5" into 3.5 and "1.234,5" into 1234.5.
An instance method of java.util.Scanner, available since Java 5 (JDK 1.5). A Scanner reads from any source (System.in for keyboard, a String, or a file) with identical parsing logic; pass the source to new Scanner(...) after import java.util.Scanner; and call sc.useLocale(...).
Syntax
Import java.util.Locale and chain useLocale(...) right after creating your scanner.
Java
Scanner sc = new Scanner("1.234,5").useLocale(Locale.GERMANY);
double val = sc.nextDouble(); // 1234.5
Call
What it does
sc.useLocale(Locale.US)
Uses . for decimals and , for thousands grouping.
sc.useLocale(Locale.GERMANY)
Uses , for decimals and . for thousands grouping.
sc.useLocale(Locale.FRANCE)
Uses , for decimals in French-formatted input.
Calling useLocale(Locale.US) is standard defensive practice whenever parsing machine-generated files, CSV exports, or tutorial inputs containing dot decimals.
Library declarations
Java
// java.util.Scanner
public Scanner useLocale(Locale locale)
Parameters
Parameter
Description
locale
A Locale instance (such as Locale.US or Locale.GERMANY) defining number syntax.
Return Value
Return Value
Description
Scanner
The same scanner instance, for convenient method chaining.
Throws
Nothing. It does not check whether the scanner is closed.