Get to know the Floating-point weirdness - Java Language Basics

Java examples for Language Basics:float

Description

Get to know the Floating-point weirdness

Demo Code

import java.text.NumberFormat;

public class Main {
  public static void main(String[] args) {
    float x = 0.1f;
    NumberFormat nf = NumberFormat.getNumberInstance();
    nf.setMinimumFractionDigits(10);/*from ww  w  .  ja  v a2s. c om*/
    
    System.out.println(x);
    System.out.println(nf.format(x));
  }

}

Related Tutorials