|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
$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! |
|
#2
|
|||
|
|||
|
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- |
|
#3
|
|||
|
|||
|
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:
__________________
__________________________________________________ _ Wil Moore III, MCP | Integrations Specialist | Senior Consultant Are You Listed...? | DigitallySmooth Inc. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > $variable=10.00; displays as whole. Why? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|