May 14, 2010 at 1:00am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
char * KandM(uint32 geld)
{
char *buf = new char [10];
if (geld > 999999)
{
// Miljoenen
sprintf(buf, "%.1fm" , geld / 1000000);
}
else if (geld > 999)
{
// Duizenden
sprintf(buf, "%.1fk" , geld / 1000);
}
else
{
// Honderden
sprintf(buf, "%i" , geld);
}
return buf;
}
and
char *test = KandM(c->transported);
is it safe to cast a function with return like this ?
or could it cause any kind of trouble ?
Since im not a pro at C++..
edit: when testing it the numbers gone wild..
an issue i couldnt solve.. maybe any of you can see the mistake ?
Last edited on May 14, 2010 at 1:22am UTC
May 14, 2010 at 1:48am UTC
Thnx for the fast reply !
but found whats wrong..
instead of tranfering into a text with %s i did it with %i..
little dumb :p
anyway, thanks for the tips!
May 14, 2010 at 2:18am UTC
Nah its not in this thread, but:
sprintf(test, "# [Company:%s] [Cargo:%s] [Passengers:%s] [Mail:%s]",c->name, kcar, kpax, kmail);
anyway.. you said deleting the new char..
Where should i do that.. because if i delete it before the return it will be faulty.. when i add it after the return it wont be handled..
also got a new issue.. when the number is above 999 it just saids 0.0k ...
tried this :
char *buf = new char[10];
Money rekendgeld = geld;
if (geld > 999999)
{
// Miljoenen
sprintf(buf, "%.1fm", rekendgeld / 1000000);
}
else if (geld > 999)
{
// Duizenden
sprintf(buf, "%.1fk", rekendgeld / 1000);
}
else
{
// Honderden
sprintf(buf, "%i", rekendgeld);
}
return buf;
but also returned 0.0k if higher then 999...
Last edited on May 14, 2010 at 12:51pm UTC
May 14, 2010 at 12:28pm UTC
It has to be handled. I gave you an example above. Good luck!