简体   繁体   中英

Read Thousandths Digit and Inrement Hundredths Digit if Nonzero (C++)

I have a list of doubles, and I need to analyze each number and do the following:

1) Check thousandths digit. 2) If ^ nonzero, round the hundredths digit and maintain the rest of the number.

So going by this:

10.111567 would become 10.121567

Alternatively:

10.110567 would remain 10.110567 because the thousandths digit is zero.

You should do exactly what you wrote in question's topic: Read Thousandths Digit and Increment Hundredths Digit if Nonzero

double val = 13.412412;
int thousandsDigit = (val*1000)%10;
if (thousandsDigit != 0) {
  val+= 0.01;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM