php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16511 wrong division: 18/21=0.857142857142861
Submitted: 2002-04-09 08:03 UTC Modified: 2002-04-09 10:05 UTC
From: sutter at ecology dot at Assigned:
Status: Closed Package: Variables related
PHP Version: 4.1.2 OS: linux 2.2.12, apache 1.3.23
Private report: No CVE-ID: None
 [2002-04-09 08:03 UTC] sutter at ecology dot at
echo (18/21);
returns 0.857142857142861.
right is 0.86;

my configure command: 
 './configure' '--prefix=/usr' '--with-config-file-path=/etc' '--disable-debug' '--enable-pic' '--enable-inline-optimization' '--with-apxs=/usr/sbin/apxs' '--disable-static' '--enable-shared' '--with-exec-dir=/usr/bin' '--with-regex=system' '--with-gettext' '--with-gd' '--with-openssl'' -with-jpeg-dir=/usr' '--with-png' '--with-zlib' '--with-gdbm' '--with-kerberos' '--with-imap-ssl' '--enable-debugger' '--enable-magic-quotes' '--enable-safe-mode' '--enable-sysvsem' '--enable-sysvshm' '--enable-track-vars' '--enable-gd-imgstrttf' '--enable-yp' '--enable-ftp' '--without-mysql' '--with-xml' '--with-ttf' '--with-gnu-ld' '--with-mysql=shared,/usr' '--with-pgsql=shared,/usr' '--with-imap=shared,/usr' '--with-ldap=shared'

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-09 08:08 UTC] derick@php.net
erm
18/21 = 0.857142857142861.

If you just want 0.86, use number_format() or round()

not a bug,

Bogus
 [2002-04-09 08:20 UTC] imajes@php.net
the really amusing thing is that THIS IS RIGHT.

if you want it to give you a rounded figure, this code will help you:

<?php

printf("%0.2f", 18/21);

?>


 [2002-04-09 09:38 UTC] sutter at ecology dot at
thanks for your comments; using number_format(),round() or printf rounds the number. but I do not really want a rounded number; and 18/21 is exactly 0.86.

philipp
 [2002-04-09 09:43 UTC] derick@php.net
0.86 * 21 = 18.06

I suggest you buy another calculater.

Derick
 [2002-04-09 09:43 UTC] imajes@php.net
which planet do you come from?
 [2002-04-09 09:44 UTC] imajes@php.net
dudes, 
18/21 is EXACTLY 0.857142857142861

EOF.
 [2002-04-09 09:48 UTC] imajes@php.net
alright, it's not exactly 0.857142857142861, but it's closer than 0.86.
 [2002-04-09 09:57 UTC] hholzgra@php.net
as the result is 1 - 1/7 it is periodic:

  ______   
0.857142



     18 : 21 = 0,857142...
      0
     --
#1   180
     168 (8x21)
     ---
#2    120
      105 (5x21)
      ---
#3     150
       147 (7x21)
       ---
#4       30
         21 (1x21)
         --
#5        90
          84 (4x21)
          --
#6         60
           42 (2x21)
           --
           18 (continue at #1)
 [2002-04-09 09:58 UTC] sutter at ecology dot at
sorry, my calculator was wrong; I tested it with two others;
 [2002-04-09 10:05 UTC] sutter at ecology dot at
thanks
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Jan 20 08:01:26 2020 UTC