Click here to Skip to main content
15,894,720 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I am getting some difficulty to remove the comma from a textBox.
The textBox receives a value (1,250) but I need it to show (1250) instead.

textBoxResult.Text = value1.ToString();


Any ideas?


Thanks a lot.

What I have tried:

Tried to use
textBoxResult.Text = value1.ToString("N0");
Posted
Updated 20-Apr-20 9:50am

Please, read these:
Custom numeric format strings | Microsoft Docs[^]
Standard numeric format strings | Microsoft Docs[^]

You need to understand that displaying numbers in specific format depends on regional settings!

C#
double dblValue = -12445.6789;
Console.WriteLine(dblValue.ToString("N", CultureInfo.InvariantCulture));
// Displays -12,445.68
Console.WriteLine(dblValue.ToString("N1",
                  CultureInfo.CreateSpecificCulture("sv-SE")));
// Displays -12 445,7
 
Share this answer
 
C#
textBoxResult.Text = textBoxResult.Text.Replace(",","");
 
Share this answer
 
Comments
Jonas Kessinger 20-Apr-20 15:49pm    
Worked perfectly, thanks a lot!
Maciej Los 20-Apr-20 15:51pm    
But it covers your real issues...
See, solution #3.
#realJSOP 20-Apr-20 20:02pm    
How does it cover his real issues?
Maciej Los 21-Apr-20 2:18am    
Well, the shortest way to explain it is to use example...
var myvalue = 1000.50;

//defult regional settings
//"En-us"
Console.WriteLine(myvalue.ToString("F1").Replace(",", ""));
//result: 1000.5

CultureInfo prs = new CultureInfo("Pl-pl");
//Polish regional stettings
Console.WriteLine(myvalue.ToString("F1", prs).Replace(",", ""));
//result: 10005


Conclusion?

Cheers!
Maciej
#realJSOP 21-Apr-20 5:25am    
His "real issue" was removing a comma from a string. His question didn't mention or imply the desire to make it culture specific. His example was to go from "1,250" to "1250". My solution is precisely what he asked for, and he marked it as "the answer".
Try
C#
textBoxResult.Text = value1.ToString("F0");
 
Share this answer
 
Comments
Maciej Los 21-Apr-20 2:20am    
Hi!
Please, see my comments to the solution #1.

Cheers,
Maciej
phil.o 21-Apr-20 3:00am    
I fully agree with you on this Maciej; not knowing which culture the OP is actually using, I just assumed the invariant culture, for which the floating format does not have any thousand separator.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900