change the decimal number to integer

i'm using C++ and i don't know how to change a decimal number to integer. for example, 7.345 WEEKS (week is the unit)..i want to change the decimal, 0.345 WEEKS to DAYS which is an integer. let say the answer will be 7 WEEKS 2 DAYS rather than 7.345 WEEKS. what coding should i write to change it? Thanks
Suppose we wish that type of the w variable is float and contains the 7.345

You can cut the fractional part:

float w = 7.345;
int week = w; // It will contain only 7

You can get the fractional part:

float tmp_d = w - week; // it will be 0.345

int d = tmp_d * 7.0; // it is rounded down

regards
A note on vocabulary:

decimal is the number system we use: it has ten digits. Both 3 and 49.2 are decimal numbers.

A whole number (and for simplicity here, integer numbers) are our counting numbers: 1, 2, 3, 4, 5, etc.

A real number is one that may contain fractional values. In computers, real numbers are often represented with the floating-point number type. Your number, 7.345, is a floating-point number.

Hope this helps.
Last edited on
Thx for us :)
Topic archived. No new replies allowed.