Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

format a number with dots and decimals in C# [closed]

Tags:

c#

asp.net

I need first .(dot) then comma(,).

like, 1234567 this is an example number or money I want it like 1.234.567,00 can anybody give me an answer.

like image 569
Krish Avatar asked Oct 20 '25 16:10

Krish


1 Answers

If the culture settings on the computer where the code is executed correspond with your wishes, you can simply use a ToString overload as:

    double d = 1234567;
    string res = d.ToString("#,##0.00");  //in the formatting, the comma always represents the group separator and the dot the decimal separator. The format part is culture independant and is replaced with the culture dependant values in runtime.

if the display has to be culture independent, you can use a specific numberformatinfo:

 var nfi = new NumberFormatInfo { NumberDecimalSeparator = ",", NumberGroupSeparator = "." };
    double d = 1234567;
    string res = d.ToString("#,##0.00", nfi); //result will always be 1.234.567,00
like image 196
Me.Name Avatar answered Oct 23 '25 06:10

Me.Name



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!