c# - String.Format is not working properly -


I have code below:

  Private string Do2Decimal (string value) {return string format}  

Here I am passing the string value as 16.32222 .
What do I know, the above code should be formatted for my value 16.32.
But it is showing output value as 16.32222 .

What's wrong with me here?

Update: I have values ​​in string format: "16.32222" Sorry, forgot to mention first.

Because you pass it a string value . The formatting will work for floating point numbers / decimals. Just parse the number on the decimal / double type depending on your requirement:

  string.format ("{0: 0 ##}", decimal. Purse (value));  

You can also use the (or TryParse) family method for secure parsing. You can also modify your method to get decimal / double type parameters And then apply formatting. It will express a better intention, IMO

if your string has . does not support your culture as well. As the NumberDecimalSeparator in the form of CultureInfo.InvariantCulture as parsing:

  string value = "16.322222"; String formatted string = string.format ("{0: 0. ##}", decimal. Purse (value, culture infoanvian culture));  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -