Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ TheIDE » U++ TheIDE: Packages » atof trucates real number with a dot but not comma on Linux
atof trucates real number with a dot but not comma on Linux [message #13528] Sun, 13 January 2008 11:21 Go to next message
cocob is currently offline  cocob
Messages: 156
Registered: January 2008
Experienced Member
Hello all,

I'm a new user of ultimate++ on Linux
I have a really blocking problem with stdlib ascii/float conversion

double val = atof(real.c_str());

when real contains "54.67" for example, the val is truncated to 54.

This source was working with an other IDE
What's the problem ?

Thanks for your help

Edit: Topic name changed by fudadmin

[Updated on: Mon, 14 January 2008 23:49] by Moderator

Report message to a moderator

Re: problem with stdlib [message #13529 is a reply to message #13528] Sun, 13 January 2008 11:33 Go to previous messageGo to next message
cocob is currently offline  cocob
Messages: 156
Registered: January 2008
Experienced Member
other information

with a console application (without any package dependency)
this work perfectly
Re: problem with stdlib [message #13530 is a reply to message #13529] Sun, 13 January 2008 14:37 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12098
Registered: November 2005
Ultimate Member
cocob wrote on Sun, 13 January 2008 05:33

other information

with a console application (without any package dependency)
this work perfectly



Hard to say. Are you sure about the content of "real"?

Perhaps there is problem with NLS. Is not it e.g. "54,67"? (',' instead of '.').

Mirek
Re: problem with stdlib [message #13532 is a reply to message #13528] Sun, 13 January 2008 15:48 Go to previous messageGo to next message
cocob is currently offline  cocob
Messages: 156
Registered: January 2008
Experienced Member
thanks for your answer

what is NLS exactly.

I'm sure of the content of the string

i tried :

char test[256];
sprintf(test, "54.67");
double reel = atof(test);


and i get the same results
Re: problem with stdlib [message #13541 is a reply to message #13528] Mon, 14 January 2008 15:40 Go to previous messageGo to next message
cocob is currently offline  cocob
Messages: 156
Registered: January 2008
Experienced Member
this is a very strange problem.

I occurs only on Linux, with an application using U++ core.

If you open one of the tutorial examples (for example grid01)
andd add this

char test[256];
sprintf(test, "54.67");
double reel = atof(test);

before App.run();

go to debugger ans you will see the problem !
Re: problem with stdlib [message #13544 is a reply to message #13528] Mon, 14 January 2008 16:54 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 801
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor

Did you try comma instead of dot?
NLS exactly = don't know, but something about locales setting of application.
Re: problem with stdlib [message #13549 is a reply to message #13544] Mon, 14 January 2008 18:07 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1298
Registered: November 2005
Location: London, UK
Senior Contributor
Administrator
mr_ped wrote on Mon, 14 January 2008 15:54

Did you try comma instead of dot?
NLS exactly = don't know, but something about locales setting of application.


NLS - Native Language Support?
Re: problem with stdlib [message #13553 is a reply to message #13528] Mon, 14 January 2008 19:07 Go to previous messageGo to next message
cocob is currently offline  cocob
Messages: 156
Registered: January 2008
Experienced Member

it works perfectly with comma !
So how can i fix it to work with dot ?

thanks
Re: problem with stdlib [message #13559 is a reply to message #13553] Mon, 14 January 2008 20:12 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1298
Registered: November 2005
Location: London, UK
Senior Contributor
Administrator
cocob wrote on Mon, 14 January 2008 18:07


it works perfectly with comma !
So how can i fix it to work with dot ?

thanks


I strongly suspect in your main macro body (at the top) add something like that:
//or console main
GUI_APP_MAIN
{
	SetLanguage(LNG_ENGLISH);
	SetDefaultCharset(CHARSET_UTF8);
...
...
Re: problem with stdlib [message #13560 is a reply to message #13528] Mon, 14 January 2008 20:25 Go to previous messageGo to next message
cocob is currently offline  cocob
Messages: 156
Registered: January 2008
Experienced Member
thanks for your help

but this don't change anything

...
Re: problem with stdlib [message #13562 is a reply to message #13560] Mon, 14 January 2008 23:43 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1298
Registered: November 2005
Location: London, UK
Senior Contributor
Administrator
I said "something like that"... Have you tried to change the language accordingly to
in Germany, Poland and some ohter countries 'decimal character' is comma, not a dot.


with
SetLanguage(LNG_?????);  //language which supports dot
SetDefaultCharset(CHARSET_????);  //charset which you get with 
a right click in the ide

Which country are you in? Or what language settings have you got in rc.conf (or similar)? (and/or What distro?)

Edit: Actually, yes, LNG_ENGLISH should support dot...
I don't have my Linux hdd at the moment, so can't test.

[Updated on: Tue, 15 January 2008 00:32]

Report message to a moderator

Re: problem with stdlib [message #13565 is a reply to message #13562] Tue, 15 January 2008 00:09 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1298
Registered: November 2005
Location: London, UK
Senior Contributor
Administrator
from http://en.wikipedia.org/wiki/Decimal_separator
dot countries:
Quote:

Countries where a dot is used to mark the radix point include:

Australia, Brunei, Botswana, Canada (English-speaking), Hong Kong, India, Ireland, Israel, Japan, Korea (both North and South), Malaysia, Mexico, New Zealand, Nigeria, Pakistan, People's Republic of China, Peru, Philippines, Singapore, Sri Lanka, Switzerland, Taiwan, Thailand, United Kingdom, United States (including insular areas), Zimbabwe.

Re: atof trucates real number with a dot but not comma on Linux [message #13576 is a reply to message #13528] Tue, 15 January 2008 09:45 Go to previous messageGo to next message
cocob is currently offline  cocob
Messages: 156
Registered: January 2008
Experienced Member
tanks for your help

I'm french from france.
I know we are using comma instead of dot here.
But it the first time i see atof searching for comma.

I'm already in English Language and i want i to works with dot.
Re: atof trucates real number with a dot but not comma on Linux [message #13649 is a reply to message #13528] Sat, 19 January 2008 09:59 Go to previous messageGo to next message
cocob is currently offline  cocob
Messages: 156
Registered: January 2008
Experienced Member

I never managed to solve the problem.

It means that this toolkit is unusable for me (and for many people because i don't knoaw why somebody wants atof to work with comma....)

for informations my locales configuration

LANG=fr_FR.UTF-8
LC_CTYPE="fr_FR.UTF-8"
LC_NUMERIC="fr_FR.UTF-8"
LC_TIME="fr_FR.UTF-8"
LC_COLLATE="fr_FR.UTF-8"
LC_MONETARY="fr_FR.UTF-8"
LC_MESSAGES="fr_FR.UTF-8"
LC_PAPER="fr_FR.UTF-8"
LC_NAME="fr_FR.UTF-8"
LC_ADDRESS="fr_FR.UTF-8"
LC_TELEPHONE="fr_FR.UTF-8"
LC_MEASUREMENT="fr_FR.UTF-8"
LC_IDENTIFICATION="fr_FR.UTF-8"
LC_ALL=
Re: atof trucates real number with a dot but not comma on Linux [message #13651 is a reply to message #13649] Sat, 19 January 2008 11:26 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1400
Registered: September 2007
Senior Contributor
Quote:

It means that this toolkit is unusable for me (and for many people because i don't knoaw why somebody wants atof to work with comma....)


Did you try to use atof in a normal gcc "Hello World" program, outside of U++, to see if it behaves the same way? And did you try to use ftoa to see if it generates a string with a ','?

And the only reason I would like to use ',' is because I was though like this in school (a long time ago).
Re: atof trucates real number with a dot but not comma on Linux [message #13653 is a reply to message #13651] Sat, 19 January 2008 11:44 Go to previous messageGo to next message
cocob is currently offline  cocob
Messages: 156
Registered: January 2008
Experienced Member

Yes it works (with ',') with a gcc program without U++ and it works with U++ without core package dependency
Re: atof trucates real number with a dot but not comma on Linux [message #13656 is a reply to message #13653] Sat, 19 January 2008 14:23 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1400
Registered: September 2007
Senior Contributor
cocob wrote on Sat, 19 January 2008 11:44


Yes it works (with ',') with a gcc program without U++ and it works with U++ without core package dependency


If it works with ',' with a normal gcc program, it means that for sure is sour system default fractional part separator. IMO, if this is such a problem and you don't want to research/mess around with system locales, why not just write your own atof function?
Re: atof trucates real number with a dot but not comma on Linux [message #13660 is a reply to message #13528] Sat, 19 January 2008 15:09 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 801
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor

Basically you may hack it by changing dots to commas before atof:
#include <Core/Core.h>
using namespace UPP;
CONSOLE_APP_MAIN
{
	String real = "254.6";
	int dotindex;
	while ( (dotindex = real.Find('.')) != -1 ) real.Set(dotindex, ',');
	Cout().Put(real); Cout().PutEol();
}


Still why there's no one competent to resolve locales here is a little mystery to me.
Try to PM luzr about this thread, he should know where to look in U++ to either change locale to english, or to at least give you the decimal separator, so the upper piece of code will work in all languages. (wishful thinking)

I basically have all computers around me set to English and I hate any localized software, just because of these little problems which arise over time, so I'm not familiar with proper solution to those things.
Re: atof trucates real number with a dot but not comma on Linux [message #13661 is a reply to message #13528] Sat, 19 January 2008 15:11 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 801
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor

Allright, I found a shortcut.
Just forget about atof.

double number = UPP::ScanDouble("12.34");


The ScanDouble is hardcoded to search for dot, so it will ignore system locales.

Quote:

it means that this toolkit is unusable for me (and for many people because i don't knoaw why somebody wants atof to work with comma....)


It's actually the toolkit's function you should have looked for, and it would fix your troubles. Wink Very Happy
Re: atof trucates real number with a dot but not comma on Linux [message #13662 is a reply to message #13660] Sat, 19 January 2008 15:17 Go to previous message
zsolt is currently offline  zsolt
Messages: 590
Registered: December 2005
Location: Budapest, Hungary
Contributor
try this:
	SetLanguage(LNGFromText("enUS"));
Previous Topic: UVS2 usage
Next Topic: vsprintf() doesn't support "%I64u" format in Win32 platform?
Goto Forum:
  


Current Time: Wed Nov 13 10:39:00 CET 2019

Total time taken to generate the page: 0.02840 seconds