Re: Cannot get percentage?
You have to force float calculations by including a number with a decimal point.
Try a/b*100.0
Re: Cannot get percentage?
Netninja is right, but you need to make sure MMF understands that the values are floating point values before the division occurs.
Try ((a*1.0)/(b*1.0))*100
Re: Cannot get percentage?
just adding 0.0 at first should be enough.
Re: Cannot get percentage?
a*100.0/b is the simplest...
the ".0" forces it to use decimal places in the calculation, and the ordering means you don't have to add any extra "*1.0" or "+0.0".
Re: Cannot get percentage?
Taking this a bit farther... is there a way to show only two digits to the right of the decimal?
Re: Cannot get percentage?
floor(NUMBER * 100) / 100.0
Re: Cannot get percentage?
Won't this simply drop the value's RIGHT of the decimal point?
Re: Cannot get percentage?
Quote:
Originally Posted by Tuna
Won't this simply drop the value's RIGHT of the decimal point?
well unless i screwed something up:
1.23456 -> 123.456 -> 123 -> 1.23
so yes it technically does get rid of them but i don't think mmf has a printf/sprintf-like function
Re: Cannot get percentage?
Thanks for your assistance xyzzy...
I'm doing Floor(hits/tries)
or more accurately
set text to str$(floor(value("hits")*100.0/value("tries")))+"%"
I was getting values with 5 decimal places to the right of the decimal without the floor function. With it, I'm getting whole percentages only.
Re: Cannot get percentage?
Isn't there a length limiting feature (len() or something?)
Re: Cannot get percentage?
The problem with using len() is that in some cases, the result is actually a "whole" number. Using left$() and len() would then give bad results.
I've opted to go ahead and use floor() because it's the closest thing to what I need.
Re: Cannot get percentage?
Actually, this morning I realized that the easiest way to do this is to use the counter object and set the number of digits to the right of the decimal to 2.
So, ommit floor() and do:
value("a")*100.0/value("b")
where a = 1 and b = 3 then the counter shows 33.33
Re: Cannot get percentage?
If you want to use a string you can use FloatToString$ instead of str$. I don't remember exactly what the parameters was but you can limit the number of decimals with it.
Re: Cannot get percentage?
good suggestion... although for my needs, i actually prefer the use of the counter, i'm already using counter controls for Hits and Tries counter, so this implementation is doing great. Thanks!
Re: Cannot get percentage?
Ins't Len() for getting the length of a string??
Re: Cannot get percentage?
Re: Cannot get percentage?
Then this post and this post don't make sense.
Re: Cannot get percentage?
LB: if you convert the value to a string then get the length, it is conceivable that one could attempt to use left() to try and truncate digits on the right. Is this a good choice? Clearly, No. Using left() and len() against numbers wont end up working.
I hope this clears up what UPRISE was suggesting, and what i commented on, but this was never a consideration for my needs.