php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17611 float takes away zeros at the end
Submitted: 2002-06-05 08:40 UTC Modified: 2002-06-06 08:02 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: fredrik dot soderquist at ks dot se Assigned:
Status: Not a bug Package: Math related
PHP Version: 4.2.1 OS: Linux: Debian potato
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: fredrik dot soderquist at ks dot se
New email:
PHP Version: OS:

 

 [2002-06-05 08:40 UTC] fredrik dot soderquist at ks dot se
Sample script:
<?php

$a = "5.00";
$b = (float) $a; //returns 5
$c = (double) $a; //returns 5
$d = (real) $a; //returns 5
settype($a,"float"); //$a now returns 5 (gettype($a) returns double)

$e = "5.01";
$f = (float) $e; //returns 5.01 (gettype($f) returns double)

?>

My configure line:
./configure --prefix=/etc/php --exec-prefix=/etc/php/exec --with-sybase=/etc/freetds --with-apxs2=/etc/apache/bin/apxs --with-cpdflib=/usr/local/lib --enable-calender'

Comment:
In any ordanary programming langauge "float" always is a specified amount of numbers. Float in PHP seemes to remove the zeros. When I convert an interger (or any other type) to a floating number it should add the amount of zeros that are specified for the language. Ex: int a = 3; float a; a becomes 3.0.

You should at least be able to convert from a string such as "5.000000" to a float without it removing the zeros after the didget!


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-05 08:41 UTC] fredrik dot soderquist at ks dot se
Sample script:
<?php

$a = "5.00";
$b = (float) $a; //returns 5
$c = (double) $a; //returns 5
$d = (real) $a; //returns 5
settype($a,"float"); //$a now returns 5 (gettype($a) returns double)

$e = "5.01";
$f = (float) $e; //returns 5.01 (gettype($f) returns double)

?>

My configure line:
./configure --prefix=/etc/php --exec-prefix=/etc/php/exec
--with-sybase=/etc/freetds --with-apxs2=/etc/apache/bin/apxs
--with-cpdflib=/usr/local/lib --enable-calender

Comment:
In any ordanary programming langauge "float" always is a specified
amount of numbers. Float in PHP seemes to remove the zeros. When I
convert an interger (or any other type) to a floating number it should
add the amount of zeros that are specified for the language. Ex: int a =
3; float a; a becomes 3.0.

You should at least be able to convert from a string such as "5.000000"
to a float without it removing the zeros after the didget!
 [2002-06-06 04:23 UTC] sander@php.net
It doesn't remove them, it just doesn't display them by default. Use printf() & co or number_format().
 [2002-06-06 07:19 UTC] fredrik dot soderquist at ks dot se
I sorry for this bogus bug-report. I know understand the picture. You guys can delete this bug-report if you want.

It's seemes sooo obvious now! I fell so ashamed, i should have looked up how other languages treat float first.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 10:01:28 2024 UTC