How can I round this array with two decimal places?
string[] PA = new String[16];
for (int i = 0; i < 16; i )
PA[i] = value[i].ToString();
My knowledge about C# is low. So I need your help.
Thanks in advance.
Alexander
CodePudding user response:
PA[i] = value[i].ToString(".##");
CodePudding user response:
You can't "round" a string, and you have an array of strings. You need an array of floating-point numbers first, which you can then output with the appropriate rounding using Math.Round and format strings to control the output as required. If you're taking user input and need to convert that to an array of floating-point numbers, perhaps you need to take a look at how to parse floating-point numbers first.