简体   繁体   English

如果非零,则读取千分之一数字和增量百分之一数字 (C++)

[英]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. 1)检查千分位。 2) If ^ nonzero, round the hundredths digit and maintain the rest of the number. 2) 如果 ^ 非零,则四舍五入百分之几并保留其余数字。

So going by this:所以通过这个:

10.111567 would become 10.121567 10.111567 将变成 10.121567

Alternatively:或者:

10.110567 would remain 10.110567 because the thousandths digit is zero. 10.110567 将保持为 10.110567,因为千分位数字为零。

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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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