.net - C# Double - ToString formatting to show a value in cents with no decimal displayed -


I have a situation where I need to show dual value in two decimal places but without displaying decimal has gone. There are some situations where I would like to use the same code and would like to display the double value differently, so I was hoping that I can handle it by passing through a string format pattern.

For example, the double value can be: 11367.2232 I should have values: 1136722

Another example, the value may be 344576.3457 I should have assumed 34457635

A third example, the value may be 546788, assuming the value is 54678800

So, I want to do something like this:

  String.Format ( "{PATTERN}", dblCurrency);  

Is there any formatting pattern that is round at both decimal places and strips the decimal from being displayed?

First , with a few exceptions (this is). To represent such a volume, you should actually use decimal .

Second , rounding and display formatting are different functions, and your code should be expressed separately. string.Format () does not provide a format format mask that both, but easily find what you are looking for:

  Decimal amount = 11367.3456meter string.format ("{0: 0}", amount * 100);  

The output will be:

  1136735  

d format specification numerical Exits without any divisive value and no number after decimal point. You can only use ToString () , but I think the format specifier tells the intent more clearly.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -