简体   繁体   English

如果负十进制值的语句范围

[英]If statements on negative decimal values ranges

I am quite new to C# and I want to do an if condition on a number range of a negative value eg if(percentage is equals to -60 to -80 ) then DoWork, my question is , How do I check using an if statement, as switches doesn't allow checks on decimal values. 我是C#的新手,我想对一个负值的数字范围执行if条件,例如if(percentage等于-60至-80)然后执行DoWork,我的问题是,如何使用if语句检查,因为开关不允许检查十进制值。 -60 to -80 means (negative 61 up till negative 81) as my condition, how can I achieve this in C#, any help will be greatly appreciated ,like I said I am still new to the .Net world. -60到-80表示(从负61到负81)作为我的条件,我该如何在C#中实现这一点,将非常感谢您的帮助,就像我说过自己对.Net世界还很陌生。

if(value >= -80 && value <= -60) {
  doWork();
}

I'm guessing when you say 'decimal value ranges' and percentages, you're doing the calculation, so in that case: 我猜想当您说“小数值范围”和百分比时,您正在进行计算,因此在这种情况下:

if( x >= -.81 && x <= -.61) { //do something }

otherwise, it would be: 否则,它将是:

if( x >= -81 && x <= -61) { //do something }

if(number >= -80.0f && number <= -60.0f)
{
     // Do stuff
}
if(a >= -80 && a <= -60) {
  DoWork();
}

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

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