Extracting a numerical value with a comma

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • laredotornado@zipmail.com

    #1

    Extracting a numerical value with a comma

    Hi,

    I have a string value, "1,250" (one thousand, two hundred and fifty).
    Is there a PHP function I can apply to this string that will give me
    the value 1250 in a variable? I've tried "intval", but I get a value
    of 1 (one), at least in PHP 4.

    Thanks for any help, - Dave

  • David Haynes

    #2
    Re: Extracting a numerical value with a comma

    laredotornado@z ipmail.com wrote:[color=blue]
    > Hi,
    >
    > I have a string value, "1,250" (one thousand, two hundred and fifty).
    > Is there a PHP function I can apply to this string that will give me
    > the value 1250 in a variable? I've tried "intval", but I get a value
    > of 1 (one), at least in PHP 4.
    >
    > Thanks for any help, - Dave
    >[/color]

    <?php
    $foo = "1,250";
    $bar = intval(str_repl ace(',', '', $foo) );

    printf("foo = %s, bar = %d\n", $foo, $bar);
    ?>

    -david-

    Comment

    Working...