开发者

Datatypes and screwy results PHP/C#/WinForms

I am having a lot of issues with the Decimal datatype in PHP and WinForms (C#). See, I have built a website and an Order and inventory management app for a client, but often the values will get all screwy. And I'm interested in how you handle pricing, discounts, freight. Do you use float, double decimal?

I swear, I had less troubles when I first started learning PHP and used VARCHAR for pricing! (And I'm not exagerating)

In my clients database, let's say I have the following:

Column Name     Column Name     Column Name     Column Name 开发者_StackOverflow 
Price           Quantity         Discount        LineTotal

ALl columns are of the decimal datatype, except for Quantity. Quantity column is int.

And when I'm doing very basic calculations, like:

$LineTotal = $Price * $Quantity;

I get stupid results, like this:

5.98888
7.
9.111
0.4442

And, worst of all, often it will just completely remove numbers from the calculation:

If for example the result of a multiplication is (or should be): 4.92

I'll go have a look in the database, and it'll say: 4

Where's my .92 cents?

What can be causing this? Am I doing something wrong?


AFAIK there is no decimal type support in PHP. So the question is probably about what type really is in $LineTotal, $Price and $Quantity variables. Consider investigation using: http://php.net/manual/en/function.gettype.php


Umm I'm not sure about PHP but when I had weird stuff happening as well when I used decimal types and C#. So I just use double now.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜