Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / dbText simple question

Author
Message
CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 26th Sep 2010 22:57
How do I get dbText to display floats??

That's my code, anyone know how?

I want coke, not Pepsi!
Dodga
14
Years of Service
User Offline
Joined: 12th Dec 2009
Location:
Posted: 26th Sep 2010 23:16
char str[128];

float x;

sprintf(str, "%d", dbObjectPositionX(1));
dbText(1,1 str);

or

dbText(1,1 dbStr(x));
^Causes memory leaks but good for small programs
Dodga
14
Years of Service
User Offline
Joined: 12th Dec 2009
Location:
Posted: 26th Sep 2010 23:18
Honestly this stuff is all found easily on google.
CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 27th Sep 2010 00:39
Alright thanks I will start using google.

I want coke, not Pepsi!
CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 30th Sep 2010 01:52
Ok, I found something else with this, I am using this code to display it:
dbText(0,0,dbStr(x));
dbText(0,10,dbStr(y));
dbText(0,20,dbStr(z));
but my variable is a float (which I need it to be) but I don't want it to DISPLAY the decimal places, or maybe just to 1 or 2 places.

I want coke, not Pepsi!
puppyofkosh
17
Years of Service
User Offline
Joined: 9th Jan 2007
Location:
Posted: 30th Sep 2010 02:44
You could cast it to int and then display it. So your code would look like



But I would avoid using dbStr, and just go with using sprintf_s
CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 30th Sep 2010 03:39
thanks

I want coke, not Pepsi!
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 30th Sep 2010 11:23
With the sprintf command you can specify in the format string how many decimal digits you want to display. E.g. %.2f will display two digits after the decimal point.

http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/

Login to post a reply

Server time is: 2024-11-19 18:44:11
Your offset time is: 2024-11-19 18:44:11