How to plug in a variable for BCMath?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jackson Scott Peebles

    How to plug in a variable for BCMath?

    Hello everyone! I could really use some help with BCMath, which I have
    just begun a project with. I require it's high-accuracy for a
    calculator of mine, but I need to plug in a variable. Now, when I try this:
    <?php
    echo bcmul('1', '$var', 99); // 1;
    ?>
    It doesn't work! This probably makes sense to you gurus out there, but
    I don't know too much about PHP, I'm just starting. How the heck do you
    plug in a variable in BCMath? One of you experts, PLEASE help me! The
    deadline for the project is coming up soon... and I need the accuracy of
    BCMath for a fact! Thanks, and please reply if you know!
  • Jerry Stuckle

    #2
    Re: How to plug in a variable for BCMath?

    Jackson Scott Peebles wrote:[color=blue]
    > Hello everyone! I could really use some help with BCMath, which I have
    > just begun a project with. I require it's high-accuracy for a
    > calculator of mine, but I need to plug in a variable. Now, when I try this:
    > <?php
    > echo bcmul('1', '$var', 99); // 1;
    > ?>
    > It doesn't work! This probably makes sense to you gurus out there, but
    > I don't know too much about PHP, I'm just starting. How the heck do you
    > plug in a variable in BCMath? One of you experts, PLEASE help me! The
    > deadline for the project is coming up soon... and I need the accuracy of
    > BCMath for a fact! Thanks, and please reply if you know![/color]

    That's because you're trying to multiple the string '1' by the string '$var' -
    (the string dollar sign, vee, etc.), not the contents of $var as a string.

    $var itself needs to be a string. If it's a numeric value, you should still get
    automatic conversion to a string. But if not, you can also use:

    echo bcmul('1', (string)$var, 99);

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    Working...