|
List Info
Thread: float in php
|
|
| float in php |

|
2006-10-19 01:06:56 |
Hello,
I'm trying to convert an int into a float in php. For
example: I get
this value: 1065353216 which represents 1.00 in float.
I tried:
* $floatValue = (float)$intValue;
* settype($intValue,"float");
* settype(&$intValue,"float");
but nothing works. They all return the initial $intValue.
When I do a
gettype($floatValue), they all return me double.
The reason I want to do that is to port some C++ code into
php. Does
anyone know a solution?
--~--~---------~--~----~------------~-------~--~----~
This group is managed and maintained by the development
staff at 360 PSG. An enterprise application development
company utilizing open-source technologies for todays
small-to-medium size businesses.
For information or project assistance please visit :
http://www.360psg.com
You received this message because you are subscribed to the
Google Groups "Professional PHP Developers" group.
To post to this group, send email to Professional-PHP googlegroups.com
To unsubscribe from this group, send email to
Professional-PHP-unsubscribe googlegroups.com
For more options, visit this group at http:
//groups.google.com/group/Professional-PHP
-~----------~----~----~----~------~----~------~--~---
|
|
| float in php |

|
2006-10-19 06:02:10 |
Quite honestly PHP isn't a programming language so the need
to convert
the numbers as such has never arised. The only way I can
think of is to
do some heavy string parsing which will cost you some
processor time.
I'll try and come up with a function.
Gaurav
Dan wrote:
> Hello,
>
> I'm trying to convert an int into a float in php. For
example: I get
> this value: 1065353216 which represents 1.00 in float.
>
> I tried:
> * $floatValue = (float)$intValue;
> * settype($intValue,"float");
> * settype(&$intValue,"float");
> but nothing works. They all return the initial
$intValue. When I do a
> gettype($floatValue), they all return me double.
>
> The reason I want to do that is to port some C++ code
into php. Does
> anyone know a solution?
>
>
> >
>
>
--~--~---------~--~----~------------~-------~--~----~
This group is managed and maintained by the development
staff at 360 PSG. An enterprise application development
company utilizing open-source technologies for todays
small-to-medium size businesses.
For information or project assistance please visit :
http://www.360psg.com
You received this message because you are subscribed to the
Google Groups "Professional PHP Developers" group.
To post to this group, send email to Professional-PHP googlegroups.com
To unsubscribe from this group, send email to
Professional-PHP-unsubscribe googlegroups.com
For more options, visit this group at http:
//groups.google.com/group/Professional-PHP
-~----------~----~----~----~------~----~------~--~---
|
|
| float in php |

|
2006-10-19 12:11:50 |
On 10/19/06, Dan <danlevan gmail.com> wrote:
> I'm trying to convert an int into a float in php. For
example: I get
> this value: 1065353216 which represents 1.00 in float.
I'm just curious, how the heck 1065353216, an integer, get's
converted
to 1.00 ???
The only thing I can think of is that you insert a
"." after the first
1 and THEN you have a float.
Cuz 1065353216 can be a float value as well, what makes a
float
DEFINITLY is the decimal portion, and 1065353216 has no
decimal
portion what-so-ever, does it ?
So something like this could do your trick:
$float=$number.'.'.substr($number,1);
This would transform "1065353216" into
"1.065353216" and NOW you have
a decimal portion. With some number formating functions you
can the
get your "1.00" format.
--
Gustavo Carreno
---
< If you know Red Hat you know Red Hat,
If you know Slackware you know Linux >
--~--~---------~--~----~------------~-------~--~----~
This group is managed and maintained by the development
staff at 360 PSG. An enterprise application development
company utilizing open-source technologies for todays
small-to-medium size businesses.
For information or project assistance please visit :
http://www.360psg.com
You received this message because you are subscribed to the
Google Groups "Professional PHP Developers" group.
To post to this group, send email to Professional-PHP googlegroups.com
To unsubscribe from this group, send email to
Professional-PHP-unsubscribe googlegroups.com
For more options, visit this group at http:
//groups.google.com/group/Professional-PHP
-~----------~----~----~----~------~----~------~--~---
|
|
| float in php |

|
2006-10-20 14:33:52 |
|
|
| float in php |

|
2006-10-20 14:36:18 |
|
Dan was a little mistaken, the number isn't an int, but a decimal
number. It gets converted to 1.00 in float as per the IEEE single
precision (i'm hoping he's using single precision) specification.
Gaurav
Gustavo Carreno wrote:
mail.gmail.com"
type="cite">
On 10/19/06, Dan gmail.com"><danlevan gmail.com> wrote:
I'm trying to convert an int into a float in php. For example: I get
this value: 1065353216 which represents 1.00 in float.
I'm just curious, how the heck 1065353216, an integer, get's converted
to 1.00 ???
The only thing I can think of is that you insert a "." after the first
1 and THEN you have a float.
Cuz 1065353216 can be a float value as well, what makes a float
DEFINITLY is the decimal portion, and 1065353216 has no decimal
portion what-so-ever, does it ?
So something like this could do your trick:
$float=$number.'.'.substr($number,1);
This would transform "1065353216" into "1.065353216" and NOW you have
a decimal portion. With some number formating functions you can the
get your "1.00" format.
--~--~---------~--~----~------------~-------~--~----~
This group is managed and maintained by the development staff at 360 PSG. An enterprise application development company utilizing open-source technologies for todays small-to-medium size businesses.
For information or project assistance please visit :
http://www.360psg.com
You received this message because you are subscribed to the Google Groups "Professional PHP Developers" group.
To post to this group, send email to Professional-PHP googlegroups.com
To unsubscribe from this group, send email to Professional-PHP-unsubscribe googlegroups.com
For more options, visit this group at http://groups.google.com/group/Professional-PHP -~----------~----~----~----~------~----~------~--~---
|
| float in php |

|
2006-10-20 23:03:23 |
On 10/20/06, Gaurav Arora <gauravsworld gmail.com> wrote:
> I have attached the script ...
Errr, no attachement on this message...
Cuz I sure want to understand this Single Precision stuff...
--
Gustavo Carreno
---
< If you know Red Hat you know Red Hat,
If you know Slackware you know Linux >
--~--~---------~--~----~------------~-------~--~----~
This group is managed and maintained by the development
staff at 360 PSG. An enterprise application development
company utilizing open-source technologies for todays
small-to-medium size businesses.
For information or project assistance please visit :
http://www.360psg.com
You received this message because you are subscribed to the
Google Groups "Professional PHP Developers" group.
To post to this group, send email to Professional-PHP googlegroups.com
To unsubscribe from this group, send email to
Professional-PHP-unsubscribe googlegroups.com
For more options, visit this group at http:
//groups.google.com/group/Professional-PHP
-~----------~----~----~----~------~----~------~--~---
|
|
| float in php |

|
2006-10-20 23:46:23 |
|
|
| float in php |

|
2006-10-22 14:22:29 |
On 10/21/06, Gaurav Arora <gauravsworld gmail.com> wrote:
> I have attached it again.
I suspect that something is wrong with email version of the
groups,
cuz I had to go tho the groups site to get the attached
file...
I've got it now !! Thanks !!
--
Gustavo Carreno
---
< If you know Red Hat you know Red Hat,
If you know Slackware you know Linux >
--~--~---------~--~----~------------~-------~--~----~
This group is managed and maintained by the development
staff at 360 PSG. An enterprise application development
company utilizing open-source technologies for todays
small-to-medium size businesses.
For information or project assistance please visit :
http://www.360psg.com
You received this message because you are subscribed to the
Google Groups "Professional PHP Developers" group.
To post to this group, send email to Professional-PHP googlegroups.com
To unsubscribe from this group, send email to
Professional-PHP-unsubscribe googlegroups.com
For more options, visit this group at http:
//groups.google.com/group/Professional-PHP
-~----------~----~----~----~------~----~------~--~---
|
|
[1-8]
|
|