Professional Web Applications Themes

how to keep decimals from rounding - PHP Development

Is there a way to surpress round() or number_format() from rounding decimal places? I have a value of ".253338" being returned via a calc function. I take that value and multiply by 100 because I want "25.333" to be displayed. I've used round(), sprintf(), and number_format() and each of them rounds the value up. I had a problem with precision earlier which I solved...my 'precision' setting in php.ini was set too low. Is there something in php.ini that controls rounding? Any heads up are appreciated! Thanks, ~Rob...

  1. #1

    Default how to keep decimals from rounding

    Is there a way to surpress round() or number_format() from rounding
    decimal places?

    I have a value of ".253338" being returned via a calc function.

    I take that value and multiply by 100 because I want "25.333" to be
    displayed.

    I've used round(), sprintf(), and number_format() and each of them
    rounds the value up.

    I had a problem with precision earlier which I solved...my 'precision'
    setting in php.ini was set too low. Is there something in php.ini that
    controls rounding?

    Any heads up are appreciated!

    Thanks,

    ~Rob
    Rob Yelvington Guest

  2. #2

    Default Re: how to keep decimals from rounding

    use floor(), I think that rounds it down... ceil() rounds it up...

    --
    // DvDmanDT
    MSN: [email]dvdmandthotmail.com[/email]
    Mail: [email]dvdmandttelia.com[/email]
    "Rob Yelvington" <robertyelvington.net> skrev i meddelandet
    news:20030825202127.895.qmailpb1.pair.com...
    > Is there a way to surpress round() or number_format() from rounding
    > decimal places?
    >
    > I have a value of ".253338" being returned via a calc function.
    >
    > I take that value and multiply by 100 because I want "25.333" to be
    > displayed.
    >
    > I've used round(), sprintf(), and number_format() and each of them
    > rounds the value up.
    >
    > I had a problem with precision earlier which I solved...my 'precision'
    > setting in php.ini was set too low. Is there something in php.ini that
    > controls rounding?
    >
    > Any heads up are appreciated!
    >
    > Thanks,
    >
    > ~Rob
    Dvdmandt Guest

  3. #3

    Default Re: [PHP] how to keep decimals from rounding

    * Thus wrote Rob Yelvington (robertyelvington.net):
    > Is there a way to surpress round() or number_format() from rounding
    > decimal places?
    >
    > I have a value of ".253338" being returned via a calc function.
    >
    > I take that value and multiply by 100 because I want "25.333" to be
    > displayed.
    >
    > I've used round(), sprintf(), and number_format() and each of them
    > rounds the value up.
    One would expect sprintf not too round, but, behold, it does.
    According to bugs.php.net, it is not a bug.
    >
    > I had a problem with precision earlier which I solved...my 'precision'
    > setting in php.ini was set too low. Is there something in php.ini that
    > controls rounding?
    >
    > Any heads up are appreciated!
    Perhaps by truncating the string to your precision that you desire.

    Curt
    --
    "I used to think I was indecisive, but now I'm not so sure."
    Curt Zirzow Guest

  4. #4

    Default Re: [PHP] how to keep decimals from rounding

    Curt, thanks for the reply and the suggestion. Truncating is exactly
    what I will do.

    Thanks!

    ~Rob

    Curt Zirzow wrote:
    > * Thus wrote Rob Yelvington (robertyelvington.net):
    >
    >>Is there a way to surpress round() or number_format() from rounding
    >>decimal places?
    >>
    >>I have a value of ".253338" being returned via a calc function.
    >>
    >>I take that value and multiply by 100 because I want "25.333" to be
    >>displayed.
    >>
    >>I've used round(), sprintf(), and number_format() and each of them
    >>rounds the value up.
    >
    >
    > One would expect sprintf not too round, but, behold, it does.
    > According to bugs.php.net, it is not a bug.
    >
    >
    >>I had a problem with precision earlier which I solved...my 'precision'
    >>setting in php.ini was set too low. Is there something in php.ini that
    >>controls rounding?
    >>
    >>Any heads up are appreciated!
    >
    >
    > Perhaps by truncating the string to your precision that you desire.
    >
    > Curt
    Rob Yelvington Guest

Similar Threads

  1. decimals in InDesign
    By Lesley_Arenas@adobeforums.com in forum Adobe Indesign Macintosh
    Replies: 23
    Last Post: September 30th, 02:17 PM
  2. MOD operator and decimals
    By Michael Hewlett in forum Coldfusion - Getting Started
    Replies: 2
    Last Post: July 27th, 09:09 AM
  3. CFCHART AND DECIMALS
    By jgarciam in forum Coldfusion - Advanced Techniques
    Replies: 0
    Last Post: May 12th, 08:19 AM
  4. Decimals not Getting into ASP
    By msnews.microsoft.com in forum ASP Database
    Replies: 0
    Last Post: July 15th, 07:44 PM
  5. Problem with decimals
    By Al Campagna in forum Microsoft Access
    Replies: 0
    Last Post: July 11th, 10:39 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139