CRover - 1 year ago 126

C++ Question

I'm trying to get the first two digits after the decimal point of a number and the check to see if they are equal to each other and, at the same time, not equal to 0.

**I know how to do the checking** stuff but **I have no idea how to select the first two digits after the decimal point**.

Using setprecision would give me the number entirely, not just the two digits after the decimal point.

For example:

`i = 3.141592`

cout << setprecision(3) << i

would output 3.14,

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

You could use the floor function from the **std** library

```
int(i*100 - (floor(i))*100)
```

Here is a good example webpage: http://en.cppreference.com/w/cpp/numeric/math/floor

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**