Page 1 of 1

Something that confuses me

PostPosted: Mon Apr 02, 2012 4:55 pm
by lcl
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?

Re: Something that confuses me

PostPosted: Mon Apr 02, 2012 5:31 pm
by Hblade
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);

Re: Something that confuses me

PostPosted: Mon Apr 02, 2012 6:34 pm
by Game A Gogo
Code: Select all
sprintf(text, "%03d%%", (int)((float)real_fps/64*100));

Re: Something that confuses me

PostPosted: Mon Apr 02, 2012 7:18 pm
by Hblade
Ya learn something new every day. :) Awesome work Gag, +1

Re: Something that confuses me

PostPosted: Mon Apr 02, 2012 8:51 pm
by lcl
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