"Gizmo" <sc***********@hotmail.com> wrote in message

news:bi**********@newsg4.svr.pol.co.uk...

Hi there i was wondering if any one new to a function that rounds up a
float to so many decimal places. I have a number in bytes and converting it to

mb's and gb's but once its converted i need to be able to do it to 2
decimal places.

An admittingly rather clumsy approach would be to multiply your

float/double by 10^x, convert to long, convert back to float/double and

divide by 10^x. 'x' is in both cases the number of wanted decimal places.

Note that this works only for little x, since otherwise you might

quickly encounter an overflow. In your case I doubt that will be the case.

Also, I am not too sure if you really need to round the numbers. If you

are converting to MB's and GB's so you can display the value on screen

somehow, I would suggest you leave the floats/doubles unrounded and let the

conversion function (ie. int to string) do the work. Like yo can do with

(s)printf:

sprintf (mystring, "You have %.02f GB left", fGB);

hth

--

jb

(replace y with x if you want to reply by e-mail)