Question Locked

java reference to a static method

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

NumberFormat nf=NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(6);

what does the above code mean?
whats the nf reference refering to?

2 replies

by geosan

The code means that you are invoking a method that belongs to the class not an instance of a class. The method will return a NumberFormat instance which defaults to the number format of the current locale.
Since NumberFormat is an abstract class, the instance of the NumberFormat class that you get when invoking the NumberFormat.getNumberInstance will provide you an interface for formatting and parsing numbers for the current locale.

You can change your locale by getting the instance like this
NumberFormat nf = NumberFormat.getInstance(Locale.FRENCH);

This discussion is closed to new replies.