How do I remove the DECIMAL part of a number

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bonymuscles
    New Member
    • Aug 2007
    • 4

    How do I remove the DECIMAL part of a number

    Hi ppl...

    Hope ur havin a good day... here''s my doubt...

    I need to remove the decimal part of a number declared as DOUBLE. I can NOT change the type. I need to remove jus the decimal part... any easy solutions to this? I have a way by using the looping.. But a short idea is what I am looking for...

    Hoep some one can solve this... :)

    Thanks,
    Bones'n'Muscles ...
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    Originally posted by bonymuscles
    Hi ppl...

    Hope ur havin a good day... here''s my doubt...

    I need to remove the decimal part of a number declared as DOUBLE. I can NOT change the type. I need to remove jus the decimal part... any easy solutions to this? I have a way by using the looping.. But a short idea is what I am looking for...

    Hoep some one can solve this... :)

    Thanks,
    Bones'n'Muscles ...
    You can do this.

    [code=java]
    double d = 12345.6789;
    d = (double)((int)d );
    [/code]

    Have a try with this.
    I think it may work.

    Debasis Jana

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by dmjpro
      You can do this.

      [code=java]
      double d = 12345.6789;
      d = (double)((int)d );
      [/code]

      Have a try with this.
      I think it may work.

      Debasis Jana
      That doesn't work; try d=1e42, it's a mathematical integer but it won't fit in an int.
      Use Math.rint() instead.

      kind regards,

      Jos

      Comment

      • dmjpro
        Top Contributor
        • Jan 2007
        • 2476

        #4
        Originally posted by JosAH
        That doesn't work; try d=1e42, it's a mathematical integer but it won't fit in an int.
        Use Math.rint() instead.

        kind regards,

        Jos

        Yeah that's right.
        Thanks for your Suggestion

        Debasis Jana

        Comment

        Working...