Something that confuses me

Non-platform specific questions.

Something that confuses me

Postby lcl » Mon Apr 02, 2012 4:55 pm

How come this code shows only 0 in my text actor?
Code: Select all
sprintf(text, "%i", round(real_fps/64)*100);

My games fps is set to 64 and I'm trying to make the actor show the percentage of the fps.
I've tried it in many ways and only time that I got close to what I want was with this code:
Code: Select all
sprintf(text, "%f", (float)real_fps/64*100);

But it shows the number in this format: 75.000000
And I don't want those 0's to be there, but when using float there is no way to get them away.
So, can someone explain me what is wrong with the first code?
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Something that confuses me

Postby Hblade » Mon Apr 02, 2012 5:31 pm

you need to define a variable with those atributes, a simple int will fix :) Like this:
Code: Select all
int a=round(real_fps/64)*100;
sprintf(text, "%i", a);
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Something that confuses me

Postby Game A Gogo » Mon Apr 02, 2012 6:34 pm

Code: Select all
sprintf(text, "%03d%%", (int)((float)real_fps/64*100));
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: Something that confuses me

Postby Hblade » Mon Apr 02, 2012 7:18 pm

Ya learn something new every day. :) Awesome work Gag, +1
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Something that confuses me

Postby lcl » Mon Apr 02, 2012 8:51 pm

Thanks guys! :D

@Gag: I was really going to ask you what those %'s after the %03d do until I tried the code without them and remembered. xD
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest