首页 \ 问答 \ 将int除以10舍入为最接近的int(Rounding up an int divided by 10 to nearest int)

将int除以10舍入为最接近的int(Rounding up an int divided by 10 to nearest int)

我想将int除以10得到一个最接近舍入的整数,所以12应该给1,17应该给2

继承我的代码:

int BonusValue;
int Str;

BonusValue = Convert.ToInt32(Math.Round(Convert.ToDouble(Str) / 10));

这会有用吗?


I want to divide an int by 10 and get a whole number closest to rounded one, so 12 should give 1 and 17 should give 2

Heres my code:

int BonusValue;
int Str;

BonusValue = Convert.ToInt32(Math.Round(Convert.ToDouble(Str) / 10));

Will this work?


原文:https://stackoverflow.com/questions/39618601
更新时间:2023-08-17 17:08

最满意答案

Saxon通常会对全局变量使用惰性求值。 例外情况是启用了运行时跟踪(如果在IDE中进行调试,则可以执行此操作); 然后切换到急切的评估,使调试更容易处理。


Saxon will normally use lazy evaluation for global variables. The exception is if run-time tracing is enabled (which may be done if you are debugging in an IDE); it then switches to eager evaluation to make debugging more tractable.

相关问答

更多
  • Saxon通常会对全局变量使用惰性求值。 例外情况是启用了运行时跟踪(如果在IDE中进行调试,则可以执行此操作); 然后切换到急切的评估,使调试更容易处理。 Saxon will normally use lazy evaluation for global variables. The exception is if run-time tracing is enabled (which may be done if you are debugging in an IDE); it then switche ...
  • 我们不知道真正的问题是什么,但是我们通过比较这个项目和我们有的其他项目文件找到了一个解决方案。 解决方法是在文本编辑器中打开.Shared.vcxitems文件,并将其替换为: 有了这个
    你需要更换: INPUT := *.s 有: INPUT := $(wildcard *.s) 第一个导致立即将*.s分配给INPUT ,这是您不想要的。 第二个导致立即分配由$(wildcard *.s)扩展产生的文件名列表,这是你想要的。 请参见4.4.1通配符示例并注意: 定义变量时不会发生通配符扩展。 因此,如果你这样写: objects = *.o 那么变量对象的值就是实际的字符串'* .o'。 [...]要将对象设置为扩展,请使用: objects := $(wildcard *.o) ...
  • 如果你想通过IEnumerable<'T>实现这个(使其变得懒惰),那么它肯定会有些必要,因为用于迭代输入的IEnumerator<'T>类型势在必行。 但其余的可以写成使用序列表达式的递归函数。 以下是懒惰的第一级(它产生每个组懒惰),但它不产生组的元素懒洋洋的(我认为这将有非常微妙的语义): /// Group adjacent elements of 'input' according to the /// keys produced by the key selector function 'f' ...
  • 并行性适用于整个流水线,因此您无法真正控制在并行Stream应用limit()之前要执行的操作。 唯一的保证是limit()后面的内容只会在保留的元素上执行。 两者之间的差异可能是由于某些实现细节或其他Stream特征。 事实上,通过播放SIZED特性,您可以轻松颠倒行为。 看起来,当Stream具有已知大小时,只处理2个元素。 因此,例如,应用简单的filter()将失去列表版本的大小: completeFirstTwoElements( Stream.of("list one", "li ...
  • 生成器表达式返回一个迭代器,您只能迭代一次。 尝试在第一次之后迭代迭代器将始终将其视为空。 A generator expression returns an iterator, which you can only iterate over once. Attempts to iterate over an iterator after the first time will always see it as empty.
  • 这里,lazy val toMap是函数的内部变量。 它不会在函数调用之间保留。 这可能是一个更好的例子(我们将lazy val作为类成员,我们可以证明它只被评估一次): case class LazyMapDemo(aparam : Array[(String, String)]) { lazy val toMap = processMap(aparam) def giveLazyMap = toMap def processMap(aparam : Array[(String, ...
  • Seq是IEnumerable与大方便的功能集合。 每个地图功能(和相关)从一开始就评估序列。 您可以在开头将序列转换为列表或数组: let quotes = getFundsClosingPrice dbFunds |> List.ofSeq 或者您可以使用Seq.cache Seq is IEnumerable with big collection of handy functions. Each map function (and related) evaluate the sequence fr ...
  • 第一步显然是doubleMe(doubleMe([1,2,3])) = doubleMe(2:doubleMe[2,3]) 实际上并不明显! 为了区别, doubleMe' = doubleMe 并考虑 doubleMe' $ doubleMe [1,2,3] 正如你所说,第一步的唯一原因,即 ≡ doubleMe' $ 2 : doubleMe [2,3] 是因为doubleMe'需要能够将它的参数与[]或_:_匹配。 为此,运行时开始评估doubleMe [1,2,3] ,即一个递归步骤。 这产生 ...
  • 您可以使用alias_method存储[]的原始实现,然后在重写的方法中引用它。 这是一个使用猴子补丁的工作实现。 class Hash alias_method :old_brackets, :[] def [](member) value = old_brackets(member) # Delegate to old implementation self[member] = value.call if value.respond_to?(:call) value ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)