Easy question (beginner)

Postby guilly on Fri Nov 26, 2004 9:59 am


I have a string variable with a numeric content, and I want to multiply it with a float number (that is, StringVariable * FloatNumber). Note that the float number is not a variable.

I tried many ways but I get weird results (the resulting number has the decimal point two positions ahead).

Any suggestions? Thank you!
Posts: 3
Joined: Mon Jun 30, 2003 8:32 am

Postby Mikael on Fri Nov 26, 2004 12:22 pm

I don't know if this is any help to you:

@cid "STF1";
@ver "1.0";
@dbname "StringXFloat";
@name "StringXFloat";
string testString = "123";
float result;
result = (int) testString * 7.3;//cast the string as an integer - or a float - by stating: (variable type)variable name
alert("Result = " + format(result,3));//state the number of decimal places to display with 'format(variable name,number of decimal places)'

I'd love to know how you got the program to run without casting your string variable first. When I tried, I got an alert saying, 'Attempt to multiply strings'.

Posts: 156
Joined: Sun Apr 13, 2003 9:19 am
Location: Denmark

Postby guilly on Sun Nov 28, 2004 7:38 pm


That is very close to what I actually do (I do data casting, so I do not get the annoying "cannot multply strings" message).

It might seem to me that the problem is coming from the Ccontrol library, with which I was experimenting with.

This is my code (sorry, quite long).

<font color="blue">
@cid "tr01";
@name "Training 01";
@dbname "tr01";

include "Ccontrols.c"

Chandle Boton, Euros, Pesetas;

main() {

int e;
float xEuros,xPesetas;

text(10,10,"Conversor EURO/PTA (Training)");

Boton = Cbutton(50,100,65,12,1,5);
Csetcontent( Boton, "Convertir" );
Cdraw( Boton );

Euros = Cedit(14,30,40,2,2,0);
Csetcontent( Euros, "Euros" );
Cdraw( Euros );

Pesetas = Cedit(67,30,40,2,2,0);
Csetcontent( Pesetas, "0" );
Cdraw( Pesetas );

while(1) {
e = event(1);
if(Cevent(Boton,e)) {
Csetcontent( Pesetas, xEuros );
Cdraw( Pesetas ); }
else if(Cevent(Euros,e)) {
xEuros = (float)Cgetcontent(Euros);
xEuros = format(xEuros, 2); }
else if(Cevent(Pesetas,e));


}</font id="blue">

Yes yes, I know, it is another bloody Euroconverter. Don't worry I won't release it to the public. I just made it for learning reasons.

Getting back to the point, has anyone encountered this problem when using Ccontrols? Did I do anything wrong?.
Posts: 3
Joined: Mon Jun 30, 2003 8:32 am

Return to PocketC for Palm OS KB

Who is online

Users browsing this forum: No registered users and 1 guest