0

私はphpとmysqlに不慣れです..&私は45,000または21,000のようなデータベースにお金を保存したいです...。

現在、データ型decimal(50,2)を使用していますが、45,000を入力すると45しか表示されません...

私が45000を入れたら...それならそれは大丈夫です.......しかし私はこのように45,000を入れたいです...

どのデータ型を使用する必要がありますか...正しく表示されますか?

varchar(50)を使用すると、そのデータを並べ替えることができません...それが問題です...。

提案をお願いします。

ありがとう

4

2 に答える 2

1

PHPでusefieldtypedecimal(10,2)を使用し、money_format ()を使用するだけです

于 2013-03-07T04:04:16.030 に答える
0

これを使って

 <?php
 function money($value) {
     return "$".number_format($value);
 }

 $money = 2000.00;

 echo money($money);

 // returns $2,000.00

 ?>

以下の機能を使用してください

$amount = '100000';
$amount = moneyFormatIndia( $amount );
echo $amount;

function moneyFormatIndia($num){
$explrestunits = "" ;
if(strlen($num)>3){
    $lastthree = substr($num, strlen($num)-3, strlen($num));
    $restunits = substr($num, 0, strlen($num)-3); // extracts the last three digits
    $restunits = (strlen($restunits)%2 == 1)?"0".$restunits:$restunits; // explodes the remaining digits in 2's formats, adds a zero in the beginning to maintain the 2's grouping.
    $expunit = str_split($restunits, 2);
    for($i=0; $i<sizeof($expunit); $i++){
        // creates each of the 2's group and adds a comma to the end
        if($i==0)
        {
            $explrestunits .= (int)$expunit[$i].","; // if is first value , convert into integer
        }else{
            $explrestunits .= $expunit[$i].",";
        }
    }
    $thecash = $explrestunits.$lastthree;
} else {
    $thecash = $num;
}
return $thecash; // writes the final format where $currency is the currency symbol.
}

// output 1,00,000

http://codepad.viper-7.com/ptxvrU

于 2013-03-07T04:05:33.113 に答える