[Solved] How to round two decimals [closed]


You have your string:

string str = "4.29 x 4.30 x 2.58mm";

Maybe remove the mm

str = str.Replace("mm", "");

Split them:

string[] nums = str.Split(new[] { " x " }, StringSplitOptions.None);

Round them:

Math.Round(Double, Int32)

Rounds a double-precision floating-point value to a specified number of fractional digits, and rounds midpoint values to the nearest even number.

foreach(string n in nums)
{
    n = Math.Round(Convert.ToDouble(n), 1).ToString();
}

2

solved How to round two decimals [closed]