English 中文(简体)
MySQL DECIMAL Hand in PHP
原标题:MySQL DECIMAL handling in PHP

正如大家共同讨论的那样(例如,见,在MySQL中,将0.00001用于需要精确性/正确性的领域,例如账户平衡。)

I was wondering however, how PHP handles these values and, if they are internally handled as floats, if there is still a problem when reading these values from the database, doing some calculations and writing them back again. If so, how can we force PHP to keep precision in tact?

最佳回答

这些变量很可能是最初在购买力平价中的一种扼杀(从MySQL结果物体读)。 一般来说,不能依靠PHP的浮动点数据类型来保持所需的准确的折旧值。 您应使用一种任意的数学图书馆,如GMP。 (如果你唱出结果物体的一行,通过<代码>)。 DECIMAL中适当构造者的栏目价值,然后使用你使用的图书馆提供的职能。

更深入: 页: 1 你们想把这种想法带进PHP,来做一些事情。 页: 1 您将问题排入一个联系阵列。 假设该行的数值为2.5674。 您的阵列现为array(MyDecimal => 2.5674 )(编号为示)。 您使用(如我能说明的那样)gmp_init(,将这一指示转换为全球机制的资源。 现在,你可以利用其他全球监测方案的职能,用该数字做数学。 如果你想要储存全球监测项目编号,你可以将其改为使用<代码>gmp_strval(<>>/code>(如果你使用能够处理全球监测方案资源的数据库抽象层,则不必这样做)。

问题回答

You could try using the arbitrary precision features:

rel=“nofollow”>http://php.net/manual/en/book.bc.php

你们的另一种选择是,在需要展示时,储存作为国际信使的价值观,然后转换(即隔100)。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签