# 如何在C＃中将数字四舍五入到小数点后两位？

### 13 Solutions collect form web for “如何在C＃中将数字四舍五入到小数点后两位？”

` `decimal a = 1.994444M; Math.Round(a, 2); //returns 1.99 decimal b = 1.995555M; Math.Round(b, 2); //returns 2.00` `

` `Math.Round(a, 2, MidpointRounding.ToEven);` `

` `twoDec = Math.Round(val, 2)` `

` `> (1.7289).ToString("#.##") "1.73"` `

` `> Math.Round((Decimal)x, 2) 1.73m` `

//转换成两位小数

` `String.Format("{0:0.00}", 140.6767554); // "140.67" String.Format("{0:0.00}", 140.1); // "140.10" String.Format("{0:0.00}", 140); // "140.00" Double d = 140.6767554; Double dc = Math.Round((Double)d, 2); // 140.67 decimal d = 140.6767554M; decimal dc = Math.Round(d, 2); // 140.67` `

=========

` `// just two decimal places String.Format("{0:0.##}", 123.4567); // "123.46" String.Format("{0:0.##}", 123.4); // "123.4" String.Format("{0:0.##}", 123.0); // "123"` `

` `String.Format("{0:0.0#}", 123.4567) // "123.46" String.Format("{0:0.0#}", 123.4) // "123.4" String.Format("{0:0.0#}", 123.0) // "123.0"` `

` `label8.Text = valor_cuota .ToString("N2") ;` `

` ` Imports System.Math round(label8.text,2)` `

stringa =“10.65678”;

` ` public double RoundDown(double number, int decimalPlaces) { return Math.Floor(number * Math.Pow(10, decimalPlaces)) / Math.Pow(10, decimalPlaces); }` `

Math.Floor（123456.646 * 100）/ 100会返回123456.64

` `decimal d1 = (decimal)1.125; Math.Round(d1, 2).Dump(); // returns 1.12 d1.ToString("#.##").Dump(); // returns "1.13" decimal d2 = (decimal)1.1251; Math.Round(d2, 2).Dump(); // returns 1.13 d2.ToString("#.##").Dump(); // returns "1.13"` `