CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2004
    Posts
    186

    Angry Problem with variable being cast to int

    I get a float value from a xml file and I assign this value to a variable

    $value = 13.80;

    When I do number_format($value,2,".",","); I get NULL. Any ideas why?

    When I try echo empty($value) ? '0' : $value; I get 13.80 showing itīs not null/empty.

    I am using PHP 5.3.13
    Last edited by rogernem; June 26th, 2012 at 04:37 PM.

  2. #2
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster PeejAvery has a reputation beyond repute (3000+) PeejAvery has a reputation beyond repute (3000+) PeejAvery has a reputation beyond repute (3000+) PeejAvery has a reputation beyond repute (3000+) PeejAvery has a reputation beyond repute (3000+) PeejAvery has a reputation beyond repute (3000+) PeejAvery has a reputation beyond repute (3000+) PeejAvery has a reputation beyond repute (3000+) PeejAvery has a reputation beyond repute (3000+) PeejAvery has a reputation beyond repute (3000+) PeejAvery has a reputation beyond repute (3000+)
    Join Date
    May 2002
    Posts
    10,798

    Re: Problem with variable being cast to int

    You must be doing something else then...because there's nothing wrong and it works.

    Note that you don't need the period or comma because those are already the default parameters.

    PHP Code:
    <?php
    $value 
    13.80;
    $value number_format($value2);
    echo empty(
    $value) ? '0' $value;
    ?>
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts



HTML5 Development Center

Click Here to Expand Forum to Full Width