我该如何将一个数字的下一个50转
How can I round to the next 50 of a number?
我正在努力调试我的工资计算器,我想将变量舍入到最近的50个,但不包括100。
例如,我有变量23324.60,我需要一个等于23350.00的公式。
这是要符合以下有关AR税收计算的指令。
"由于净应税收入少于50,000,我们将收入达到$ 50的中股(23,350.00美元((中额为23,300.00美元和$ 23,400.00(。"
,因为您可以将每一个零件绕过50个奇数,所以您可以将其视为圆形 down 到完整的100s,然后添加50。例如,这将使200和299.99均投向250
我基于这种方法的解决方案是:
double rounded_income(double income) {
return 50.0 + 100.0 * floor(income / 100.0);
}
floor
功能在<cmath>
标头中提供。另一种方法是从整数类型中来回走动,但会有许多缺点,包括更糟糕的可读性。
#include <iostream>
#include <math.h>
using namespace std;
int getRoundUp50(float value)
{
return ceil(value * 0.02) * 50;
}
int main()
{
cout << getRoundUp50(120.5) << endl;
cout << getRoundUp50(125.0) << endl;
return 0;
}
结果:
150
150
相关文章:
- 如何(从固定列表中)选择一个数字序列,该序列将与目标数字相加
- 如何获取一个数字的前3位
- 以C++输出一个数字三角形
- 反转一个数字程序不起作用,为什么?
- 如何让用户在 c++ 中选择一个数字
- 输出一个数字,该数字可能是三种类型之一
- C++在不使用pow或循环的情况下计算一个数字的幂
- 我必须更改我的数字最后一个数字和第一个数字,但不要使用仅带有整数或循环的函数.例如从 12345 到 52341
- 找到所有与自己求和的数字X的快速方法,去掉一个数字得到N
- C++[递归]将一个数字写成2的升序之和
- 试图找到一个数字的平方根,但代码不起作用。C++
- 我没有得到一个数字作为输出,而是一个表情符号
- 我的代码应该接受一个数字,并返回字母等级或"Grade is not valid"但 else 语句不起作用
- 将一个数字拆分为多个数字,每个数字只有一个有效位
- 你怎么编码,如果x不等于一个数字,程序就会退出
- 如何将整数数组相乘得到一个数字?
- 为无符号字符* 分配一个数字
- 如何以更有效的方式检查一个数字是否是素数?
- C++显示两个区间之间的数字的程序检查一个数字是否可以表示为两个素数的总和
- 字符串和双精度的麻烦,等值后再得到一个数字