どうも、ちょげ(@chogetarou)です。
数値の小数点第2位を四捨五入する方法を紹介します。
方法

数値の小数点第二位を四捨五入するには、Math.Round()を使います。
まず、Math.Round()を呼び出します。
そして、Math.Round()の第1引数に数値、第2引数に「1」を指定します。
Math.Round(number, 1);
上記のMath.Round()は、第1引数の数値の小数点第2位を四捨五入した数値を返します。
使用例
using System;
public class Example
{
public static void Main()
{
double num1 = Math.Round(1.1412, 2);
double num2 = Math.Round(1.455, 2);
double num3 = Math.Round(25.714, 2);
Console.WriteLine(num1); //1,14
Console.WriteLine(num2); //1.46
Console.WriteLine(num3); //25.71
}
}
コメント