• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Rounding up (Was Re: Another newbie question...)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rounding up (Was Re: Another newbie question...)


  • Subject: Re: Rounding up (Was Re: Another newbie question...)
  • From: Esteban <email@hidden>
  • Date: Mon, 28 Jan 2002 21:04:17 -0800

Hi,

Made a mistake in my code listing.
See my comment below.
-------------------------
double myvalue = 123.456, result_value;
int temp_value;

temp_value = (int) (123.456 * 100); //multiplying by 100 gets us 12345.6 which we then cast as an int to get rid of the .6 fractional part.
//the casting to int of a double is very important in the line above
//temp_value should equal 12345


There should be some rounding up going on around here, sorry overlooked that part :)
where you round up the temp_value so it ends up as 123.46

result_value = (double)(temp_value/100); //we dont really need to cast back to a double, but the casting is there for illustration purposes.

//result_value should be equal 123.45, and we have rounded to hundredths successfully.

-----------------------


Just look at NSDecimalNumber as John C. and I suggested :) (damn he beat me to response)

-Esteban


References: 
 >Rounding up (Was Re: Another newbie question...) (From: Esteban <email@hidden>)

  • Prev by Date: Re: VCARD NSPasteboard type
  • Next by Date: Re: VCARD NSPasteboard type
  • Previous by thread: Rounding up (Was Re: Another newbie question...)
  • Next by thread: Re: Another newbie question...
  • Index(es):
    • Date
    • Thread