Help - Search - Members - Calendar
Full Version: Division with decimal places
Hydrogenaudio Forums > Hosted Forums > foobar2000 > General - (fb2k)
Overlord
Think this is the right forum for this....

I'm writing up a script for my track info panel and there are one or two things I'm trying to do involving division that just aren't working, because foobar's $div() method drops all decimal places, and $mul() ignores them!

Random examples:

$div(3,2) : That should spit out 1.5. Instead, it gives 1.
$div(9,5) : Should be 1.8. Again, it displays 1.
$mul(9,1.5) : Gives 9, where it should be 13.5.

$div() obviously just removes anything after decimal points, and because of this my track %age played indicator doesn't work (it shows 0%, all the way up to the end of the track, where it shows 100%, because halfway through the calculation the number is as a decimal - eg. 80% has the track percentage as 0.8 at a point). Likewise, I have a method that calculates the filesize from the number of bytes using some division - because of the dropping of decimal places, it reports an inaccurate size. $mul(), by displaying 9, is just ignoring the .5 after it. I've tried with various numbers, I'm positive this is what it's doing.

Are there any division and multiplication methods, compatible with foobar 0.8.3 scripting (yeah, yeah. I'm not upgrading to 0.9 until certain plugins I need are ported), that support decimal places, or will I have to wait until 0.9 (or beyond!) for this?

Thanks.
KalleGuld
I'm no expert, but I haven't seen the use of decimals anywhere in foobar 0,.9 scripting, so I guess you just have to rewrite some of your code.

IMO it's very handy, since almost all number-inputs are integers anyway.

For your percent thing, use $muldiv(%_time_elapsed_seconds%,100,%_total_time_seconds%)' %'
Zoom
This is the string I used to use when I had a playback percentage:

CODE
$substr($num($muldiv(%playback_time_seconds%,1000,%length_seconds%),3),1,2).
$substr($num($muldiv(%playback_time_seconds%,1000,%length_seconds%),3),3,3)'%'


Similar to the one above, but there are always three numbers and a decimal place. i.e. 05.7%, the only problem with it is that 100% is displayed as 10.0%. I imagine there is a longer script you could make to have it look good but this works as does the one above.

I'm not sure if there is any easier way to make it, but that's what I used.

Ok I just realized that my formatting is 0.9 specific, however, this works and shows 100% as 100% with 0.9!

CODE
$iflonger($muldiv(%playback_time_seconds%,100,%length_seconds%),2,100.0'%',
$substr($num($muldiv(%playback_time_seconds%,1000,%length_seconds%),3),1,2).
$substr($num($muldiv(%playback_time_seconds%,1000,%length_seconds%),3),3,3)'%')

My apologies for being slightly off-topic but I imagine you could convert that to 0.8.3 tag script just by changing a few things:

CODE
$iflonger($muldiv(%_time_elapsed_seconds%,100,%_total_time_seconds%),2,100.0'%',
$substr($num($muldiv(%_time_elapsed_seconds%,1000,%_total_time_seconds%),3),1,2).
$substr($num($muldiv(%_time_elapsed_seconds%,1000,%_total_time_seconds%),3),3,3)'%')


Hmm, I'm not even sure myself anymore, maybe I should just stop editing and give up? unsure.gif
Overlord
$muldiv() seems to do what I want for both the %age code and the filesize methods - cheers, guys! =)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.