converting string to float

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pipe.jack@gmail.com

    #1

    converting string to float

    I'm trying to convert string to float and my float after conversion is
    0 (zero). Here is my code:

    $c = $currencies->format($cart->show_total() );
    echo gettype($c);
    echo (float)$c;

    $c = 39.59
    gettype($c) = string
    echo (float)$c; = 0

    any other string such as "2.34" converted into float exactly the same
    way works fine.

    Thanks,
    JP

  • Kimmo Laine

    #2
    Re: converting string to float

    pipe.jack@gmail .com kirjoitti:
    I'm trying to convert string to float and my float after conversion is
    0 (zero). Here is my code:
    >
    $c = $currencies->format($cart->show_total() );
    echo gettype($c);
    echo (float)$c;
    >
    $c = 39.59
    gettype($c) = string
    echo (float)$c; = 0
    >
    any other string such as "2.34" converted into float exactly the same
    way works fine.
    >
    Thanks,
    JP
    >
    What does $currencies->format() do and why wouldn't you just use the
    $cart->show_total() ?


    --
    "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
    spam@outolempi. net | Gedoon-S @ IRCnet | rot13(xvzzb@bhg byrzcv.arg)

    Comment

    • Rik

      #3
      Re: converting string to float

      On Thu, 15 Feb 2007 18:32:15 +0100, <pipe.jack@gmai l.comwrote:
      I'm trying to convert string to float and my float after conversion is
      0 (zero). Here is my code:
      >
      $c = $currencies->format($cart->show_total() );
      echo gettype($c);
      echo (float)$c;
      >
      $c = 39.59
      gettype($c) = string
      echo (float)$c; = 0
      >
      any other string such as "2.34" converted into float exactly the same
      way works fine.
      Are you looking at this in a HTML page? If so, what does the source say?
      Someone just recently had this problem because the value was
      '<b>12.34</b>' rather then '12.34'.... Try an echo htmlentities($c );
      --
      Rik Wasmus

      Comment

      • pipe.jack@gmail.com

        #4
        Re: converting string to float

        Are you looking at this in a HTML page? If so, what does the source say?
        Someone just recently had this problem because the value was
        '<b>12.34</b>' rather then '12.34'.... Try an echo htmlentities($c );
        Thanks both of you. The htmlentities($c ) output was $12.34 caused by
        the $currencies->format() function.

        Comment

        Working...