user987316
user987316

Reputation: 942

Format double value in different locale

In my C++ project I am using string formatting as follows -

sprintf(tag, "%g", "100.88");

If I run it in English locale it maps fine. I would like to make changes to it to work in different locales. Like in German locale tag should get assigned as 100,88.

How I can achieve this?

I am looking for something similar to

system.convert.tostring(100.88 , 
                        system.globalization.culturalinfo.invariantculture)

Upvotes: 1

Views: 312

Answers (2)

Björn Pollex
Björn Pollex

Reputation: 76788

If you were using iostreams, you'd do this by imbuing the stream with the locale you want to use.

Upvotes: 2

James Kanze
James Kanze

Reputation: 153909

Use an ostringstream imbued with the locale you want.

Upvotes: 2

Related Questions