alternative bcmul()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ryu
Forum Newbie
Posts: 3
Joined: Mon May 23, 2005 12:25 am
Contact:

alternative bcmul()

Post by Ryu »

Hi,

i need an alternative function which does the same as bcmul(). Please help me.

greetz

Ryu
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Why?

Code: Select all

function bcmul_alternative($n, $m, $dec=0) {
    $value = $n * $m;
    if ($dec) {
        $value = round($value, $dec);
    }
    return $value;
}
Ryu
Forum Newbie
Posts: 3
Joined: Mon May 23, 2005 12:25 am
Contact:

Post by Ryu »

and this function does exactly the same as bcmul() ? if so, thank you. you helped me.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Well from what I read about bcmul() it just multiplies two floats and optionally rounds to X decimal places.

That's what the above does. The third paramter is optional but if given it will round to that many places. Unless I misunderstand what the function is for?
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

d11wtq wrote:Unless I misunderstand what the function is for?
Maybe BCMath isn't enabled on his server ?
Syranide
Forum Contributor
Posts: 281
Joined: Fri May 20, 2005 3:16 pm
Location: Sweden

Post by Syranide »

If you want bcmul, you want bcmul, if he wouldn't need it he would just use the multiplicator sign (or did he missunderstand the meaning of bcmul?).

bcmul btw is used for arbitrary precision mathematics, meaning that you can do calculations with virtually any number, something you CAN'T do with $n * $m, as the precision for that is about 10 digits (roughly said) if I'm not mistkaken.

I don't know, perhaps "gmp_" can do this, but it's likelt not available.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Heh now I've been educated :oops:
Ryu
Forum Newbie
Posts: 3
Joined: Mon May 23, 2005 12:25 am
Contact:

Post by Ryu »

yes the problem is that bcmath is disabled at this server. but i don't have the permission to change this.
Post Reply