Reputation: 4642
Given the input 123.45
, I'm trying to get the output 123,45
via String.Format
.
Because of the system I'm working in, the actual format strings (e.g. {0:0.00}
) are saved in a config file and transformed later down the pipeline.
Editing the config file to add a new format is "safe" and I can get this through quite quickly. Editing the actual parser later down the line is "risky" so will need a more significant QA resource and I need to avoid this.
As a result, some caveats:
string.Format(pattern, input)
. No overloads.string.Format(new System.Globalization.CultureInfo("de-DE"), "{0:0.00}", 123.45)
then I've got what I need. But I cannot pass the localisation.So can it be done?
Is there any format I can pass to string.Format
which will transform 123.45
into 123,45
?
Upvotes: 1
Views: 507
Reputation: 766
Just for the fun of it :)
double value =123.45;
Console.WriteLine(String.Format("{0:#0.00}\b\b\b,", value));
This of course only works when there is a cursor, like in the console, otherwise the backspace control characters have no effect.
Sorry, but i can't think of a real way in accomplishing this.
Upvotes: 1
Reputation: 318
If you can you multiply the input by 100 then the following should work:
double input = 123.45;
string pattern = "{0:###\\,##}";
var result = String.Format(pattern, input*100);
Upvotes: 1