Removing decimal points

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BOMEz
    New Member
    • Dec 2007
    • 40

    Removing decimal points

    I'm wondering which data type will only give me the whole number and drop off the rest of the fraction?

    For example if I have 3.14, but I just want 3, how can i get this done?
  • pronerd
    Recognized Expert Contributor
    • Nov 2006
    • 392

    #2
    There are a number of API options for controlling output formatting. This will show you what you want.

    This internationalization Java tutorial describes setting locale, isolating locale-specific data, formatting data, internationalized domain name and resource identifier
    Last edited by Nepomuk; Sep 11 '08, 07:59 AM. Reason: Added [URL] tags

    Comment

    • chaarmann
      Recognized Expert Contributor
      • Nov 2007
      • 785

      #3
      Convert the floating point number to an int.
      int result = (int) 3.14;

      You could also do it with Math.floor() or Math.ceil() or Math.round() or especially Math.rint(), depending in which way you want to cut off.

      Comment

      • samido
        New Member
        • Oct 2007
        • 52

        #4
        some titorials:

        {
        double d = 3.43;
        int x ;
        double s;
        s = x; // right
        x = s; // wrong
        x = (int)d; //write
        x = d; // wrong
        . // ???
        . // ???
        . // ???

        }

        Sam Rabophala

        Comment

        Working...