The Daily Click ::. Forums ::. Klik Coding Help ::. Changing a real value into an integer
 

Post Reply  Post Oekaki 
 

Posted By Message

Ecstazy



Registered
  04/01/2002
Points
  179

VIP Member
26th August, 2005 at 21:29:49 -

Well, I have this number, and I want to get a percentage of it, so I do value("number") * value("percent") / 100
But it seems like TGF only likes whole numbers.
So is there any way to "smooth the edges" of the number, and if I got let's say 3.41, it'll be set in the counter as a 3?

 
Amongst Strangers
http://www.create-games.com/project.asp?id=1445

Ecstazy



Registered
  04/01/2002
Points
  179

VIP Member
27th August, 2005 at 09:58:50 -

I have a number, and I want to get a percentage of it. Like if it was 10 then 50% of it would be 5.
So if I have 3 counters - one is the number (10), one is the percentage (50) and one is the future result (5) - what I did was that the future result counter equals original_number * percent / 100

Basic math, right?

But that was a simple case, say I have a number 2093 and I want 39% of it, I will get a number that's not whole, 816.27.
The counter doesn't seem to like such numbers, so how do I make it accept the result as 816?

Image Edited by the Author.

 
Amongst Strangers
http://www.create-games.com/project.asp?id=1445

Ecstazy



Registered
  04/01/2002
Points
  179

VIP Member
27th August, 2005 at 10:13:15 -

Hmm?
If I use the formula I get 0 because it's not a whole number.
I need to somehow take off the .27, like what div does.

 
Amongst Strangers
http://www.create-games.com/project.asp?id=1445

David Newton (DavidN)

Invisible

Registered
  27/10/2002
Points
  8322

Honored Admin Alumnus
27th August, 2005 at 10:30:55 -

As far as I know, MMF will truncate numbers automatically. I think the problem lies in the formula you're using - division is done before multiplication, so (value("percent") / 100) is always truncated to 0 before you multiply it.

Use extra brackets: "(value("number") * value("percent")) / 100" - multiplying up first should solve it.

 
http://www.davidn.co.nr - Games, music, living in America

Ecstazy



Registered
  04/01/2002
Points
  179

VIP Member
27th August, 2005 at 10:59:03 -

Works like a charm, thanks a lot.

 
Amongst Strangers
http://www.create-games.com/project.asp?id=1445
   

Post Reply



 



Advertisement

Worth A Click