PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 5th, 2004, 11:20 PM
the12php the12php is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 1 the12php User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
$variable=10.00; displays as whole. Why?

I Just started learning php (php newbie)

a variable value 10.00 displays as 10

I've tried $variable = round(10.00, 2)
I've delcared it a float and it still displays as a whole. I know I'm doing something wrong but can't pinpoint it.


hope someone can help

Thanks fellas!

Reply With Quote
  #2  
Old July 6th, 2004, 08:45 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 16
This is probably because php is weakly typed so just ignores the 0's after the decimal point unless they are relevent (ie have a non-zero digit after them).

Don't know if there is a way around this, what is the context its being used in?

-KM-

Reply With Quote
  #3  
Old July 7th, 2004, 03:21 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 785 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 17
kode_monkey is correct... PHP is not strongly-typed, thus, "10.00" can be represented easily as a numeric type or a string type. If it is represented as a numeric type, you only get the numbers that matter (10).

If you want to view it as 10.00 you will have to cast this into a string. The simple way is:

PHP Code:
<?php

$ten 
10.00;            

/* prints six zeros */
//printf('%f', $ten);

/* prints only two zeros */
printf('%01.2f'$ten);  

?>
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > $variable=10.00; displays as whole. Why?


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap