1. ## calculate numbers

Hi,

How can i calculate numbers and round off the decimal point to 2 decimal places?

for example i have 2 numbers 5 and 3

the result of 5 divide by 3 is 1.666666666

i want it to return me only 1.66 or 1.67 for example..

how could i go about it? and for my numbers what variable type should they be? double? float? i've tried all but i couldn't get the result i want.

2. > i want it to return me only 1.66 or 1.67 for example.
Is that what you want to print, in which case it would be something like
Code:
```    double a = 5.0 / 3.0;
cout << setprecision(3) << a << endl;```
If you really want to store the rounded results, then you need to understand that floats are approximations. So even if you round the result to 1.67, this may in fact be represented as 1.66999999 or 1.67000001 as being the nearest representable value.

3. Originally Posted by Salem
> i want it to return me only 1.66 or 1.67 for example.
Is that what you want to print, in which case it would be something like
Code:
```    double a = 5.0 / 3.0;
cout << setprecision(3) << a << endl;```
If you really want to store the rounded results, then you need to understand that floats are approximations. So even if you round the result to 1.67, this may in fact be represented as 1.66999999 or 1.67000001 as being the nearest representable value.
For printing, using only setprecision is not enough:
Code:
```    double a = 50.0 / 3.0;
cout << setprecision(3);
cout << a << endl;```
prints 16.7.

You'll need to use the "fixed" manipulator also, and specify the decimal places you want after the decimal point:
Code:
```    double a = 50.0 / 3.0;
cout << fixed << setprecision(2);
cout << a << endl;```
(This prints 16.67)

4. thanks both of u! the solution works wonders