Help - Search - Members - Calendar
Full Version: $sub and fractional numbers
Hydrogenaudio Forums > Hosted Forums > foobar2000 > Support - (fb2k)
phwip
In the title formatting $sub returns only the whole number difference of two fractional numbers. Is there any way to get a fractional result.

For example:

$puts(n1,1.5)
$puts(n2,3.9)
$sub($get(n1),$get(n2))

I would like this to display -2.4 but it just displays -2

Thanks.
billcow
Unfortunately, all the math functions in foobar are integer-only. However, if you must, you *can* hack together a pseudo-floating-point adder/whatever by using string functions to find the decimal place, remove it, do whatever, add it back in.

Generally, though, it's easier to find a more integerial (new word! yay!) method of doing what you want. The other option is to use fixed point (long story short, make everything x times bigger than what it represents, where "x" is effectifvely the precision. then when multiplying, divide the result by x, when dividing, multiply the number being divided (i haven't done anything but algebra/calc in math for years, so forgive me for not knowing the term for it) by x first, for +/-, do nothing).
phwip
Thanks billcow. I tried making everything bigger (ie. if I want 2 digits after the decimal place then multiply everything by 100 before I start).

Of course found out that I still have to make some use of string functions to move the decimal place around to get my final result because of $div returning an integer too (eg $div(82,100) returns 0, not 0.82).

So I've got there in the end by a combination of these methods.

EDIT: typo
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.