标签: rounding

将浮点数四舍五入到最接近的 <n> 倍数?

如何将浮点值舍入到最接近的“n”倍数?

例如,将 21.673 四舍五入到最接近的 8 倍数应得到 24。

并且,将 21.673 四舍五入到最接近的 4 倍数应得到 20。

我需要 JavaScript 的解决方案。

javascript rounding

-1
推荐指数
1
解决办法
891
查看次数

Ruby回合下一代

我怎样才能完成下一百个?使用Ruby 2.3.2.

48 -> 100 52 -> 100 112 -> 200

试过48.round(-2)但是那个倒了下来.Trialed一些BigDecimal值,但这让我无处可去.

ruby rounding

-1
推荐指数
1
解决办法
1053
查看次数

在python中使用`round`与`__round__`有什么不同?

在python 3中,这有效:

Celsius = [39.2, 45.2, 37.3, 37.8, 89]
Fahrenheit = map(lambda x: ((float(9/5))*x + 32).__round__(3), Celsius)

print(list(Fahrenheit))

[102.56, 113.36, 99.14, 100.04, 192.2]
Run Code Online (Sandbox Code Playgroud)

但是,这不起作用,为什么?:

Fahrenheit = map(lambda x: ((float(9/5))*x + 32).round(3), Celsius)
Run Code Online (Sandbox Code Playgroud)

此外,现在很多python脚本都不使用这种旧格式__round__,我认为这样可以使脚本看起来更干净.还有其他核心原因吗?

python lambda function rounding python-3.x

-1
推荐指数
1
解决办法
164
查看次数

Math.Round().我的数据是10.17,我怎样才能到10.50

我的数据是10.17,我希望得到10.50.这个代码我用过totQty = Math.Round(totQty, 1, MidpointRounding.ToEven)但得到10.20.

c# vb.net math rounding

-1
推荐指数
1
解决办法
138
查看次数

如何在PHP中舍入一个数字

我运行一个wooocommerce网站,重量是磅,我需要将它们转换为公斤.

我已经从一个网站下载了这个脚本,它完成了这个工作,但是它设置了很多小数的新权重,不知道如何舍入它.

我试图使用,round($new_weight, 2);但它没有采取或不确定在何处放置它或如何.

注意:我对php一无所知.此脚本是页面模板.它会在您打开它时进行更改.

<?php
/*
 *
 * Template name: wconvertor
 */
get_header();

$args = array( 'post_type' => 'product', 'posts_per_page' => 2500  );

$loop = new WP_Query( $args );

while ( $loop->have_posts() ) : $loop->the_post(); 
global $product; 

$weight= get_post_meta( get_the_ID(), '_weight', true);

if ( ! empty( $weight ) ) {

    echo "id = ".get_the_ID(). " weight = ".$weight; 

    $new_weight = $weight / 2.2 ; 
    round($new_weight,2);

    echo "<br>new weight = ".$new_weight."  ********************";

    // id , key , …
Run Code Online (Sandbox Code Playgroud)

php rounding

-1
推荐指数
1
解决办法
773
查看次数

我想在C#中将124.33到124.50和124.57到125.00之类的值四舍五入

如果doublevalue = 124.75那么
如果doublevalue = 124.25那么它应该四舍五入到125.00 然后它应该四舍五入到124.50

简而言之,小数点后大于50的数字必须舍入到100而小于50应该舍入到50

请帮我搞定这类代码

c# windows rounding winforms

-1
推荐指数
1
解决办法
113
查看次数

C#:Math Round() 产生不同的结果

我只是在浏览一些 C# 编码问题。小提琴链接在这里

问:以下代码的输出是什么?

using System;

public class Program
{
    public static void Main()
    {
        Console.WriteLine(Math.Round(6.5));
        Console.WriteLine(Math.Round(11.5));
    }
}
Run Code Online (Sandbox Code Playgroud)

6 12

这是输出。

我怀疑6.5是否是6。11.5怎么会是12?

它应该是 11 或者 6.5 应该是 7。

也许这是非常不明智的,任何建议/解释都可以帮助我清楚地理解。

c# math rounding

-1
推荐指数
1
解决办法
608
查看次数

C#中的圆积分数

我一直在搜索这个问题几个小时,但我找不到答案所以我问它:

我正在寻找一种方法或一些四舍五入25,599,99925,000,00025,599,99930,000,000:

 int num1 = 25599999;
 Console.WriteLine(RoundDown(num1, 6 /* This is the places (numbers from end that must be 0) */)) // Should return 25,000,000;
Run Code Online (Sandbox Code Playgroud)

或者向上:

 int num1 = 25599999;
 Console.WriteLine(RoundUp(num1, 6 /* This is the places (numbers from end that must be 0) */)) // Should return 30,000,000;
Run Code Online (Sandbox Code Playgroud)

注意:我不是在寻找一种舍入十进制数的方法.

.net c# int numbers rounding

-1
推荐指数
1
解决办法
117
查看次数

获取三位有效数字的方法

我想将值四舍五入为三位有效数字。我想得到如下答案:

39.07 -> 39.1
9.0712 -> 9.07
9.0071-> 9.01
0.01523 -> 0.0152
0.00150 -> 0.0015
39.01233 -> 39
Run Code Online (Sandbox Code Playgroud)

如果小数点前的有效数字超过三位,则应显示小数点前的所有数字:

11327 -> 11327
11327.314 -> 11327
11327.84 -> 11328
Run Code Online (Sandbox Code Playgroud)

ruby rounding

-1
推荐指数
1
解决办法
239
查看次数

如何在python中使用int()将数字四舍五入到其最小值

我想要的是:

if 1700 / 1000 = 1.7 = int(1) # I want this to be True
   lst.append("T")
Run Code Online (Sandbox Code Playgroud)

我的原始代码是:

if 1700 / 1000 == int(1) # This is False and I want it to be True
   lst.append("T")
Run Code Online (Sandbox Code Playgroud)

if 语句为 False,因为答案是 1.7 而不是 1。我希望这是真的。所以我希望使用 int 将 1.7 向下舍入为 1,以便 if 语句为 True。

python truncate rounding

-1
推荐指数
1
解决办法
93
查看次数

标签 统计

rounding ×10

c# ×4

math ×2

python ×2

ruby ×2

.net ×1

function ×1

int ×1

javascript ×1

lambda ×1

numbers ×1

php ×1

python-3.x ×1

truncate ×1

vb.net ×1

windows ×1

winforms ×1