decimal point

decimal point

am 16.12.2007 02:11:56 von Ron Piggott

How do I get the decimal point back when I am retrieving from a column
that is set up as:

rate decimal(4,2)

Example: Right now it is giving me 800 instead of 8.00

Ron

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: decimal point

am 16.12.2007 03:18:00 von Micah Stevens

What's your insert statement?

On 12/15/2007 05:11 PM, Ron Piggott wrote:
> How do I get the decimal point back when I am retrieving from a column
> that is set up as:
>
> rate decimal(4,2)
>
> Example: Right now it is giving me 800 instead of 8.00
>
> Ron
>
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: decimal point

am 16.12.2007 04:13:19 von Ron Piggott

INSERT INTO rate_plans VALUES ( '12', 'One Week', '1', '2', '2',
'8.00' )

When I use

$advertisement_rate = mysql_result($rate_plan_result,0,"rate");

$advertisement_rate has a value of 800 instead of 8.00 --- how can I get
my 2 decimal places back?

Ron

On Sat, 2007-12-15 at 18:18 -0800, Micah Stevens wrote:
> What's your insert statement?
>
> On 12/15/2007 05:11 PM, Ron Piggott wrote:
> > How do I get the decimal point back when I am retrieving from a column
> > that is set up as:
> >
> > rate decimal(4,2)
> >
> > Example: Right now it is giving me 800 instead of 8.00
> >
> > Ron
> >
> >

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: decimal point

am 16.12.2007 04:58:48 von Micah Stevens

--------------090805060106020901000508
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

If I make a test table with a field that is DECIMAL(4,2), I can:

INSERT INTO `testaa` ( `a` )
VALUES (
'8.00'
)

Then I can
SELECT * FROM `testaa`

I get '8.00' from the 'a' field.

It looks like you're using an abstraction library? Perhaps that's the
problem?

-Micah



On 12/15/2007 07:13 PM, Ron Piggott wrote:
> INSERT INTO rate_plans VALUES ( '12', 'One Week', '1', '2', '2',
> '8.00' )
>
> When I use
>
> $advertisement_rate = mysql_result($rate_plan_result,0,"rate");
>
> $advertisement_rate has a value of 800 instead of 8.00 --- how can I get
> my 2 decimal places back?
>
> Ron
>
> On Sat, 2007-12-15 at 18:18 -0800, Micah Stevens wrote:
>
>> What's your insert statement?
>>
>> On 12/15/2007 05:11 PM, Ron Piggott wrote:
>>
>>> How do I get the decimal point back when I am retrieving from a column
>>> that is set up as:
>>>
>>> rate decimal(4,2)
>>>
>>> Example: Right now it is giving me 800 instead of 8.00
>>>
>>> Ron
>>>
>>>
>>>
>
>

--------------090805060106020901000508--

Re: decimal point

am 16.12.2007 18:55:01 von Ron Piggott

Ok. I have this resolved.

One more question about this --- is there any way I may keep the 2
decimal places when I use math to manipulate the variable ---


$rate_plan_rate = ($rate_plan_rate / 100) * (100 - $discount);

$ 28.8

I would like the result to be $28.80

Thanks for your help Micah.

Ron

On Sat, 2007-12-15 at 19:58 -0800, Micah Stevens wrote:
> If I make a test table with a field that is DECIMAL(4,2), I can:
>
>
> INSERT INTO `testaa` ( `a` )
> VALUES (
>
> '8.00'
> )
>
> Then I can
> SELECT * FROM `testaa`
>
> I get '8.00' from the 'a' field.
>
> It looks like you're using an abstraction library? Perhaps that's the
> problem?
>
> -Micah
>
>
>
> On 12/15/2007 07:13 PM, Ron Piggott wrote:
> > INSERT INTO rate_plans VALUES ( '12', 'One Week', '1', '2', '2',
> > '8.00' )
> >
> > When I use
> >
> > $advertisement_rate = mysql_result($rate_plan_result,0,"rate");
> >
> > $advertisement_rate has a value of 800 instead of 8.00 --- how can I get
> > my 2 decimal places back?
> >
> > Ron
> >
> > On Sat, 2007-12-15 at 18:18 -0800, Micah Stevens wrote:
> >
> > > What's your insert statement?
> > >
> > > On 12/15/2007 05:11 PM, Ron Piggott wrote:
> > >
> > > > How do I get the decimal point back when I am retrieving from a column
> > > > that is set up as:
> > > >
> > > > rate decimal(4,2)
> > > >
> > > > Example: Right now it is giving me 800 instead of 8.00
> > > >
> > > > Ron
> > > >
> > > >
> > > >
> >
> >

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: decimal point

am 16.12.2007 19:08:53 von Stephen Johnson

You will lose your decimal places during normal calculations...

But you can display them back to the user using number_format.

http://php.net/number_format

Bear in mind that you should always pass the formatted number into a
different variable as you will NOT be able to perform any further
calculations on the formatted variable since it now considered a string.

Hope this helps
--
Stephen Johnson c | eh
The Lone Coder

http://www.thelonecoder.com
continuing the struggle against bad code

http://www.thumbnailresume.com
--




> From: Ron Piggott
> Organization: Acts Ministries Christian Evangelism
> Reply-To:
> Date: Sun, 16 Dec 2007 12:55:01 -0500
> To: Micah Stevens
> Cc:
> Subject: Re: [PHP-DB] decimal point
>
> Ok. I have this resolved.
>
> One more question about this --- is there any way I may keep the 2
> decimal places when I use math to manipulate the variable ---
>
>
> $rate_plan_rate = ($rate_plan_rate / 100) * (100 - $discount);
>
> $ 28.8
>
> I would like the result to be $28.80
>
> Thanks for your help Micah.
>
> Ron
>
> On Sat, 2007-12-15 at 19:58 -0800, Micah Stevens wrote:
>> If I make a test table with a field that is DECIMAL(4,2), I can:
>>
>>
>> INSERT INTO `testaa` ( `a` )
>> VALUES (
>>
>> '8.00'
>> )
>>
>> Then I can
>> SELECT * FROM `testaa`
>>
>> I get '8.00' from the 'a' field.
>>
>> It looks like you're using an abstraction library? Perhaps that's the
>> problem?
>>
>> -Micah
>>
>>
>>
>> On 12/15/2007 07:13 PM, Ron Piggott wrote:
>>> INSERT INTO rate_plans VALUES ( '12', 'One Week', '1', '2', '2',
>>> '8.00' )
>>>
>>> When I use
>>>
>>> $advertisement_rate = mysql_result($rate_plan_result,0,"rate");
>>>
>>> $advertisement_rate has a value of 800 instead of 8.00 --- how can I get
>>> my 2 decimal places back?
>>>
>>> Ron
>>>
>>> On Sat, 2007-12-15 at 18:18 -0800, Micah Stevens wrote:
>>>
>>>> What's your insert statement?
>>>>
>>>> On 12/15/2007 05:11 PM, Ron Piggott wrote:
>>>>
>>>>> How do I get the decimal point back when I am retrieving from a column
>>>>> that is set up as:
>>>>>
>>>>> rate decimal(4,2)
>>>>>
>>>>> Example: Right now it is giving me 800 instead of 8.00
>>>>>
>>>>> Ron
>>>>>
>>>>>
>>>>>
>>>
>>>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: decimal point

am 19.12.2007 17:20:28 von Micah Stevens

--------------090805080905050306040206
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit


Without trying it, I would assume php (since it's typeless) would just
cast the string back into a number? I wouldn't do it for another reason-
possible loss of accuracy.

-Micah

On 12/16/2007 10:08 AM, Stephen Johnson wrote:
> You will lose your decimal places during normal calculations...
>
> But you can display them back to the user using number_format.
>
> http://php.net/number_format
>
> Bear in mind that you should always pass the formatted number into a
> different variable as you will NOT be able to perform any further
> calculations on the formatted variable since it now considered a string.
>
> Hope this helps
> --
> Stephen Johnson c | eh
> The Lone Coder
>
> http://www.thelonecoder.com
> continuing the struggle against bad code
>
> http://www.thumbnailresume.com
> --
>
>
>
>
>
>> From: Ron Piggott
>> Organization: Acts Ministries Christian Evangelism
>> Reply-To:
>> Date: Sun, 16 Dec 2007 12:55:01 -0500
>> To: Micah Stevens
>> Cc:
>> Subject: Re: [PHP-DB] decimal point
>>
>> Ok. I have this resolved.
>>
>> One more question about this --- is there any way I may keep the 2
>> decimal places when I use math to manipulate the variable ---
>>
>>
>> $rate_plan_rate = ($rate_plan_rate / 100) * (100 - $discount);
>>
>> $ 28.8
>>
>> I would like the result to be $28.80
>>
>> Thanks for your help Micah.
>>
>> Ron
>>
>> On Sat, 2007-12-15 at 19:58 -0800, Micah Stevens wrote:
>>
>>> If I make a test table with a field that is DECIMAL(4,2), I can:
>>>
>>>
>>> INSERT INTO `testaa` ( `a` )
>>> VALUES (
>>>
>>> '8.00'
>>> )
>>>
>>> Then I can
>>> SELECT * FROM `testaa`
>>>
>>> I get '8.00' from the 'a' field.
>>>
>>> It looks like you're using an abstraction library? Perhaps that's the
>>> problem?
>>>
>>> -Micah
>>>
>>>
>>>
>>> On 12/15/2007 07:13 PM, Ron Piggott wrote:
>>>
>>>> INSERT INTO rate_plans VALUES ( '12', 'One Week', '1', '2', '2',
>>>> '8.00' )
>>>>
>>>> When I use
>>>>
>>>> $advertisement_rate = mysql_result($rate_plan_result,0,"rate");
>>>>
>>>> $advertisement_rate has a value of 800 instead of 8.00 --- how can I get
>>>> my 2 decimal places back?
>>>>
>>>> Ron
>>>>
>>>> On Sat, 2007-12-15 at 18:18 -0800, Micah Stevens wrote:
>>>>
>>>>
>>>>> What's your insert statement?
>>>>>
>>>>> On 12/15/2007 05:11 PM, Ron Piggott wrote:
>>>>>
>>>>>
>>>>>> How do I get the decimal point back when I am retrieving from a column
>>>>>> that is set up as:
>>>>>>
>>>>>> rate decimal(4,2)
>>>>>>
>>>>>> Example: Right now it is giving me 800 instead of 8.00
>>>>>>
>>>>>> Ron
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>
>>>>
>> --
>> PHP Database Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
>

--------------090805080905050306040206--