I have a line (confirm that it has a decimal expression) 0,4351242134
I want to convert to a string with two decimal places 0.44
How do I do in C #?
var probablyDecimalString = "0.4351242134"; decimal value; if (Decimal.TryParse(probablyDecimalString , out value)) Console.WriteLine ( value.ToString("0.##") ); else Console.WriteLine ("not a Decimal");
var d = decimal.Parse("0.4351242134"); Console.WriteLine(decimal.Round(d, 2));
Well, I would do:
var d = "0.4351242134"; Console.WriteLine(decimal.Parse(d).ToString("N2"));
float f = float.Parse("0.4351242134"); Console.WriteLine(string.Format("{0:0.00}", f));
See this for string.Format.
It would help
double ValBefore= 0.4351242134; double ValAfter= Math.Round(ValBefore, 2, MidpointRounding.AwayFromZero); //Rounds"up"
float myNumber = float.Parse("0.4351242134"); Console.WriteLine(string.Format("{0:f2}", myNumber ));
https://msdn.microsoft.com/en-us/library/s8s7t687.aspx
Source: https://habr.com/ru/post/923474/More articles:how to add http header in soaprequest in java - javaWordpress user user type - wordpresshttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/923471/kill-activity-when-it-comes-to-foreground&usg=ALkJrhiy_WFmDHKUw7g7ee3MZJGicAfqagJavaScript replace () Method: remove white space only at the end and at the beginning of a line - javascriptGWT MVP Update Activity Status on Place Change - mvpgolang: launch default application for pdf file in windows - windowsComponent Mapping in Railo - coldfusionHow to create translated javadoc using javadoc.exe? (not content, but structure) - javaOpening a file with spaces in Windows using the command line - command-lineThis does not work. - coldfusionAll Articles