+ 7

C++ - System default decimal point and digit grouping character

Hi SoloLearners! help is needed here ... Is there available a *standard* way to know which character is used by system as digits grouping and decimal point, and how to use those characters to format a number into a string form. e.g. 123456.789 into "123,456.789". Also, in reverse, if there is a way to convert a formatted number as string (having digits group & decimal point) to get the actual number. e.g. "123,456.789" into 123456.789. Thanks in advance friends,

11th Aug 2018, 8:09 AM
Ipang
8 Respostas
+ 2
Ipang Here is a sample code that may help. You're most welcome. https://code.sololearn.com/cDEDcV3tp0Qp/?ref=app
12th Aug 2018, 2:43 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 2
Here's what I came up with: https://code.sololearn.com/cfR7tTDQL9Ei/#cpp To convert a float into a string I used the 'std::to_string(float)' method. To do the opposite I used the 'stof(std::string)' method. Each one has the return type of std::string and float, respectively.
11th Aug 2018, 10:01 PM
Louie
Louie  - avatar
+ 2
Thank you so much for the answer Luis, however I was looking for a way to output numerical format with digit grouping for integral & floating point types (e.g. 123,456), and with decimal point for floating point types (e.g. 123,456.789). And I also need to be able to accept formatted numbers (e.g. "123,456" or "123,456.789") and convert them back to their original value paying respect to the type. Anyway mate, will you please remove that e-mail address, you probably know already that personal information exposure here is a big "No No" : ) (Edit) Thanks Louie for understanding.
12th Aug 2018, 4:32 AM
Ipang
+ 2
Ipang I think you can try the numpunct class under <locale>. The class has a function grouping which I think does what you want to do : www.cplusplus.com/reference/locale/numpunct/grouping To achieve the effect, create a locale with the setting, and activate and deactivate it as per need.
12th Aug 2018, 1:35 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 2
Kinshuk Vasisht Thanks for the link, I'll look into it, tbh I still don't know this locale thing, but I will find the way : )
12th Aug 2018, 2:32 PM
Ipang
+ 2
Kinshuk Vasisht Thanks again, I will look into that code. Actually I have some questions about the code, if it's OK I will ask in the code comments, but maybe later.
12th Aug 2018, 3:04 PM
Ipang
+ 1
In some of the programming languages Rem is used to give comment
19th Dec 2018, 3:06 AM
Easy # Tricks
Easy # Tricks - avatar
0
Yes R.E.M. is used to give comment
19th Dec 2018, 1:54 PM
Bhuvana
Bhuvana - avatar