Fixe Point Decimal Data type

--0-1441322339-1261059694=:42856
Content-Type: text/plain; charset=us-ascii

Hello,

Is there a way to represent numeric values as fixed point decimals in PHP? If not, why was this datatype not added?

I think is very important to have fixed point decimals when working with money values. This would make it much easy than having to use the BCMath functions.

If PHP had support for operator overloading then we could have easily implemented this datatype as a class:

$a = new FixPoint(34.56, 2);
$b = new FixPoint(34.55, 2);

$c = $a-$b;
echo ($c);

$c+= 3;
echo $c;
--0-1441322339-1261059694=:42856--
Raymond Irving [ Do, 17 Dezember 2009 15:21 ] [ ID #2026396 ]

Re: Fixe Point Decimal Data type

I may be over-simplifying or not completely understanding fixed point =
decimals, but would number_format work?

Take care,
Floyd

On Dec 17, 2009, at 9:21 AM, Raymond Irving wrote:

> Hello,
>
> Is there a way to represent numeric values as fixed point decimals in =
PHP? If not, why was this datatype not added?
>
> I think is very important to have fixed point decimals when working =
with money values. This would make it much easy than having to use the =
BCMath functions.
>
> If PHP had support for operator overloading then we could have easily =
implemented this datatype as a class:
>
> $a =3D new FixPoint(34.56, 2);
> $b =3D new FixPoint(34.55, 2);
>
> $c =3D $a-$b;
> echo ($c);
>
> $c+=3D 3;
> echo $c;


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Floyd Resler [ Do, 17 Dezember 2009 15:49 ] [ ID #2026397 ]

Re: Fixe Point Decimal Data type

On Thu, Dec 17, 2009 at 7:49 AM, Floyd Resler <fresler [at] adex-intl.com> wrote:
> I may be over-simplifying or not completely understanding fixed point decimals, but would number_format work?
>
> Take care,
> Floyd
>

Over-simplifying just a touch...
http://en.wikipedia.org/wiki/Floating_point_error#Accuracy_p roblems

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
LinuxManMikeC [ Do, 17 Dezember 2009 16:58 ] [ ID #2026398 ]

Re: Fixe Point Decimal Data type

On Thu, Dec 17, 2009 at 7:21 AM, Raymond Irving <xwisdom [at] yahoo.com> wrote:
> Hello,
>
> Is there a way to represent numeric values as fixed point decimals in PHP? If not, why was this datatype not added?
>
> I think is very important to have fixed point decimals when working with money values. This would make it much easy than having to use the BCMath functions.
>
> If PHP had support for operator overloading then we could have easily implemented this datatype as a class:
>
> $a = new FixPoint(34.56, 2);
> $b = new FixPoint(34.55, 2);
>
> $c = $a-$b;
> echo ($c);
>
> $c+= 3;
> echo $c;

A lack of operator overloading wouldn't stop me if I really needed
such a datatype. Besides, I'd be willing to bet a class (or several)
have already been made.

There is also a problem with your example usage of FixPoint. By
initializing the FixPoint with a float you are still at risk for
rounding errors. It would be better to initialize a FixPoint from
integers or a string if accuracy is truly paramount.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
LinuxManMikeC [ Do, 17 Dezember 2009 17:10 ] [ ID #2026399 ]
PHP » gmane.comp.php.general » Fixe Point Decimal Data type

Vorheriges Thema: $_POST is empty , but were are the variables posted??
Nächstes Thema: RE:bcompiler.so fails to load