Forums | developer.brewmp.com Forums | developer.brewmp.com

Developer

Forums

Forums:

Perhaps this seems a stupid question, but I need to convert a float into a string. Is there any way to do this ? I tried to use SNPRINTF() but it works only on integers. I need to convert from float to a string (with that number)...

Thnx !

look for FLOATTOWSTR
ruben

look for FLOATTOWSTR
ruben

Right ! It works, yet it does too much ! I need a char* type result, not an AECHAR* result, so I have to do a conversion. I read that the FLOATTOWSTR does a conversion from char* to AECHAR* internally, so ... I just have to half undo what it does :)
Thank you

Right ! It works, yet it does too much ! I need a char* type result, not an AECHAR* result, so I have to do a conversion. I read that the FLOATTOWSTR does a conversion from char* to AECHAR* internally, so ... I just have to half undo what it does :)
Thank you

see WSTRTOSTR()

see WSTRTOSTR()

Yes.
There is a problem though !
FLOATTOWSTR(val, rezultat, 4*sizeof(AECHAR));
If val is an integer value (like 50), rezultat will not contain any characters !!
If val is not integer (like 50.2), then rezultat will containt the right string (that's "50.2")
Why ?

Yes.
There is a problem though !
FLOATTOWSTR(val, rezultat, 4*sizeof(AECHAR));
If val is an integer value (like 50), rezultat will not contain any characters !!
If val is not integer (like 50.2), then rezultat will containt the right string (that's "50.2")
Why ?

Look at the API User's Guide. There are numerous helper functions. The integer will not work because FLOATTOWSTR() requires a double as its first parameter. To turn an int into a wstr, use sprintf() and strtowstr(). You have to be willing to read the manual and do some thinking as people here will quickly grow weary of spoon-feeding you the basics.

Look at the API User's Guide. There are numerous helper functions. The integer will not work because FLOATTOWSTR() requires a double as its first parameter. To turn an int into a wstr, use sprintf() and strtowstr(). You have to be willing to read the manual and do some thinking as people here will quickly grow weary of spoon-feeding you the basics.

Sometimes it seems as if people are actually trying to code under Brew to learn programming... or is it just me getting that impression?

Sometimes it seems as if people are actually trying to code under Brew to learn programming... or is it just me getting that impression?

You see, nobody knows everything from the beginning, and learning is easier with the other's help. Silly questions like the one above might upsed you and this wasn't my intention. I tried to take the short way to understanding and solving basic problems... And perhaps you also know that the API reference is quite ermetic for beginners.
Sorry for the inconvenience, I'll try to be more ... "advanced" next time... Yet it puzzels me how smart people like you can get so malicious to a simple help requirement which you can easely give.
Thank you !

You see, nobody knows everything from the beginning, and learning is easier with the other's help. Silly questions like the one above might upsed you and this wasn't my intention. I tried to take the short way to understanding and solving basic problems... And perhaps you also know that the API reference is quite ermetic for beginners.
Sorry for the inconvenience, I'll try to be more ... "advanced" next time... Yet it puzzels me how smart people like you can get so malicious to a simple help requirement which you can easely give.
Thank you !

And by the way, I forgot to tell you that I am not that stupid not to know that FLOATTOWSTR works over floats only !! But if that float is "50.0000" than the result is a blank AECHAR* string. And this I think isn't ok !
Anyways... thanks !

And by the way, I forgot to tell you that I am not that stupid not to know that FLOATTOWSTR works over floats only !! But if that float is "50.0000" than the result is a blank AECHAR* string. And this I think isn't ok !
Anyways... thanks !

irimiab:
Please accept my apology for having offended you.
I responded as I did based on the content of your message. When you said you were passing an integer value in place of a double, I took that literally.
I got impatient because I thought you would look up the functions Ruben and I told you about. In doing so, you would have found the list of helper functions, where (almost - see below) everything you need is clearly documented.
It bothers me when people ask for stuff that is easily found in the documentation, the knowledge base, the FAQ, or by searching past posts to this forum. After all, I had to learn (and continue to learn) BREW by using these resources and I'll wager that most of the people who post here are in the same bucket.
In closing, a tip:
You should never pass a literal floating point number as a parameter, else you will get the wonky results you've encountered. You must convert it to a double using WSTRTOFLOAT().
e.g.
double result = FMUL(WSTRTOFLOAT((AECHAR*)L"1.0", WSTRTOFLOAT((AECHAR*)L"2.0");
regards,
Murray

irimiab:
Please accept my apology for having offended you.
I responded as I did based on the content of your message. When you said you were passing an integer value in place of a double, I took that literally.
I got impatient because I thought you would look up the functions Ruben and I told you about. In doing so, you would have found the list of helper functions, where (almost - see below) everything you need is clearly documented.
It bothers me when people ask for stuff that is easily found in the documentation, the knowledge base, the FAQ, or by searching past posts to this forum. After all, I had to learn (and continue to learn) BREW by using these resources and I'll wager that most of the people who post here are in the same bucket.
In closing, a tip:
You should never pass a literal floating point number as a parameter, else you will get the wonky results you've encountered. You must convert it to a double using WSTRTOFLOAT().
e.g.
double result = FMUL(WSTRTOFLOAT((AECHAR*)L"1.0", WSTRTOFLOAT((AECHAR*)L"2.0");
regards,
Murray

That's ok Murray.
I think I am quite a beginner and sometimes I really have stupid questions. I appreciate your help and I hope I won't offend you or others (like Dragon :mad: ) in the future.
Thank you !

That's ok Murray.
I think I am quite a beginner and sometimes I really have stupid questions. I appreciate your help and I hope I won't offend you or others (like Dragon :mad: ) in the future.
Thank you !

I have the following code:
double val;
char* rez;
AECHAR* rez2;
val=(double)(ATOI(Value));
val=FADD(FDIV(FMUL(val,9),5),32);
rez=(char*)MALLOC(8);
rez2=(AECHAR*)MALLOC(8*sizeof(AECHAR));
FLOATTOWSTR(val, rez2, 4*sizeof(AECHAR));
WSTRTOSTR(rez2, rez, 4);
Why won't this work ?
And why does FLOATTOWSTR puts a space character before the result (if it has a result) ?
Thanks !

I have the following code:
double val;
char* rez;
AECHAR* rez2;
val=(double)(ATOI(Value));
val=FADD(FDIV(FMUL(val,9),5),32);
rez=(char*)MALLOC(8);
rez2=(AECHAR*)MALLOC(8*sizeof(AECHAR));
FLOATTOWSTR(val, rez2, 4*sizeof(AECHAR));
WSTRTOSTR(rez2, rez, 4);
Why won't this work ?
And why does FLOATTOWSTR puts a space character before the result (if it has a result) ?
Thanks !

Quote:
double val;
char* rez;
AECHAR* rez2;
val=(double)(ATOI(Value));
val=FADD(FDIV(FMUL(val,9),5),32);
rez=(char*)MALLOC(8);
rez2=(AECHAR*)MALLOC(8*sizeof(AECHAR));
FLOATTOWSTR(val, rez2, 4*sizeof(AECHAR));
WSTRTOSTR(rez2, rez, 4);
Seems to be there is a bug(or that's BREW way!) in FLOATTOWSTR function.
For example,
in your code, if you modify to the following
rez=(char*)MALLOC(32);
rez2=(AECHAR*)MALLOC(64*sizeof(AECHAR));
FLOATTOWSTR(val, rez2, 64*sizeof(AECHAR));
WSTRTOSTR(rez2, rez, 32);
you will see that 41 is placed at the end of the buffer "rez2" with preceding spaces. Now if you modify the line (for test)
FLOATTOWSTR((double)(41.01234), rez2, 32*sizeof(AECHAR));
you will see that the string is at the end of the buffer with preceding spaces.
I suppose this is not correct behavior of FLOATTOWSTR. May be after FLOATTOWSTR, you do a simple check for space and trim those spaces and then call WSTRTOSTR.
ruben

Quote:
double val;
char* rez;
AECHAR* rez2;
val=(double)(ATOI(Value));
val=FADD(FDIV(FMUL(val,9),5),32);
rez=(char*)MALLOC(8);
rez2=(AECHAR*)MALLOC(8*sizeof(AECHAR));
FLOATTOWSTR(val, rez2, 4*sizeof(AECHAR));
WSTRTOSTR(rez2, rez, 4);
Seems to be there is a bug(or that's BREW way!) in FLOATTOWSTR function.
For example,
in your code, if you modify to the following
rez=(char*)MALLOC(32);
rez2=(AECHAR*)MALLOC(64*sizeof(AECHAR));
FLOATTOWSTR(val, rez2, 64*sizeof(AECHAR));
WSTRTOSTR(rez2, rez, 32);
you will see that 41 is placed at the end of the buffer "rez2" with preceding spaces. Now if you modify the line (for test)
FLOATTOWSTR((double)(41.01234), rez2, 32*sizeof(AECHAR));
you will see that the string is at the end of the buffer with preceding spaces.
I suppose this is not correct behavior of FLOATTOWSTR. May be after FLOATTOWSTR, you do a simple check for space and trim those spaces and then call WSTRTOSTR.
ruben

Thank you for the answer, Ruben. I have already trimmed the spaces. But this only solved half of the problem.
I still have the following problem:
When I have a double value without decimals, the FLOATTOWSTR converts it to " " (nothing! just spaces!). This can't be a normal behaviour either ! Is this another bug, or another face of the same bug ? :)
Thanks

Thank you for the answer, Ruben. I have already trimmed the spaces. But this only solved half of the problem.
I still have the following problem:
When I have a double value without decimals, the FLOATTOWSTR converts it to " " (nothing! just spaces!). This can't be a normal behaviour either ! Is this another bug, or another face of the same bug ? :)
Thanks

I think that's the same problem. Increase the buffer size, I guess at the end of the buffer you will see the string.
ruben

I think that's the same problem. Increase the buffer size, I guess at the end of the buffer you will see the string.
ruben

Apparently FLOATTOWSTR is equivalent to:
sprintf(rez, "%12g", val);
STRTOWSTR(rez, rez2, sz);
A quick fix is to use a length>=13 for your buffers.
HTH
Radu

Apparently FLOATTOWSTR is equivalent to:
sprintf(rez, "%12g", val);
STRTOWSTR(rez, rez2, sz);
A quick fix is to use a length>=13 for your buffers.
HTH
Radu

Indeed, a buffer long enough is the solution. The nasty thing is that I need to solve the space-eliminating issue (a little bit too much effort for such a simple thing).
(Anyway, a bug fix from Qualcomm would be good ;) )
Thank you

Indeed, a buffer long enough is the solution. The nasty thing is that I need to solve the space-eliminating issue (a little bit too much effort for such a simple thing).
(Anyway, a bug fix from Qualcomm would be good ;) )
Thank you

Quote:
The nasty thing is that I need to solve the space-eliminating issue (a little bit too much effort for such a simple thing).
You can do that easily by using WSTRRCHR for ' ' (space) and then copy the string in to a new buffer.
ruben

Quote:
The nasty thing is that I need to solve the space-eliminating issue (a little bit too much effort for such a simple thing).
You can do that easily by using WSTRRCHR for ' ' (space) and then copy the string in to a new buffer.
ruben

Yes, I know that, I have already done that, it works ok.
I have trimmed the decimals too, except the first one, because I don't need such a precision. These things should have been implemented in BREW, for FLOATTOWSTR:
- no spaces in the resulting string, or spaces at the end
- conversion only with a specified number of decimals (another paramether in FLOATTOWSTR).
- also, a function like FLOATTOSTR would be necessary, thus eliminating this repeating action of str->WSTR and backwars
Thank you Ruben for your help !

Yes, I know that, I have already done that, it works ok.
I have trimmed the decimals too, except the first one, because I don't need such a precision. These things should have been implemented in BREW, for FLOATTOWSTR:
- no spaces in the resulting string, or spaces at the end
- conversion only with a specified number of decimals (another paramether in FLOATTOWSTR).
- also, a function like FLOATTOSTR would be necessary, thus eliminating this repeating action of str->WSTR and backwars
Thank you Ruben for your help !

You can always write it yourself if the provided function doesn't have the functionality you're looking for. That way you also remove your dependencies on a particular operating system/compiler.

You can always write it yourself if the provided function doesn't have the functionality you're looking for. That way you also remove your dependencies on a particular operating system/compiler.