简体   繁体   English

如何获得有条件的 output?

[英]how can I get an conditional output?

I have two integers ( input & output )我有两个整数(输入和 output)

when input >= 1 and <= 100000 , output will 20
when input >= 100001 and <= 200000 , output will 30
when input >= 200001 and <= 300000 , output will 40
when input >= 300001 and <= 400000 , output will 50
when input >= 400001 and <= 500000 , output will 60
...
...
and so on.

Max range of input is unlimited最大输入范围无限制

How can I manage it in C#如何在 C# 中管理它

output = (ceil(input/100000) +1)*10

The ceil function basically rounds above a float to an integer. ceil function 基本上在浮点数上方四舍五入到 integer。

Simple arithemtic along with integer division should do the trick简单的算术以及 integer 除法应该可以解决问题

var output = (input / 100000) * 10 + 20;

If the input is a floating point or decimal already then use Math.Floor如果input已经是浮点数或小数,则使用Math.Floor

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

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