Thread: how to remove zero after decimal point

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    2

    how to remove zero after decimal point

    I want to make a function whic will remove all the tralling zeros from a numeric data type.

    Means i just want to pass the numeric data as an input and want the reslut like this:-

    1. Eg.:- 123.0000
    Relust:- 123

    2. Eg:- 123.0100
    Result:- 123.01

  2. #2
    Lean Mean Coding Machine KONI's Avatar
    Join Date
    Mar 2007
    Location
    Luxembourg, Europe
    Posts
    444
    Quote Originally Posted by abhay_m8 View Post
    I want to make a function whic will remove all the tralling zeros from a numeric data type.

    Means i just want to pass the numeric data as an input and want the reslut like this:-

    1. Eg.:- 123.0000
    Relust:- 123

    2. Eg:- 123.0100
    Result:- 123.01
    This is not a problem with the numeric data, since the trailing zeros aren't stored in memory. This is only a problem of correct formatted display.

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    27

    IF...

    ...you meant that you wanted it to display correctly, you simply use the functions, fixed, showpoint, and setprecision. These require <iomanip>.
    Other than that, you can get it to show only relevent numbers, but I'd have to search, and that's your job. I remember I used to have the exact opposite problem, it would only display the decimal value, and no trailing zeros!
    If you didn't mean that you were trying to do that and worried about storage, as he said, a float is a float, it'll take up the same space (unless you go outside the value range) as any other float regardless of zeros or not, since the memory is allocated to said float.

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318

    Talking LOL

    Quote Originally Posted by abhay_m8 View Post
    reslut
    Relust
    Result
    Third time's a charm. Though I must admit the first two miss-spellings were rather ammusing!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. hex to binary,hex to decimal
    By groovy in forum C Programming
    Replies: 2
    Last Post: 01-25-2006, 02:14 AM
  2. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 12:07 PM
  3. observing whether a point is in a triangle???
    By hebele in forum C++ Programming
    Replies: 1
    Last Post: 05-19-2003, 03:38 PM
  4. fixed point / floating point
    By confuted in forum Game Programming
    Replies: 4
    Last Post: 08-13-2002, 01:25 PM