1 頁 (共 1 頁)

[外掛] cash mod 兌換錯誤

發表於 : 2005-02-27 16:23
richer
參考連結: http://phpbb-tw.net/phpbb/viewtopic.php?t=30132

假設有貨幣A 貨幣B
兌換比例 A : B = 500 : 1

妳去對換 250 的 A 到 B
結果會A 扣除 250 元 B 增加 1 元
兌換 0.5 的 B 到 A
結果會 B 沒有扣除 A 增加 250 元

修正辦法:
 -----[開啟]-----

代碼: 選擇全部

cash.php
 -----[找到]-----

代碼: 選擇全部

					$converted_amount = (($convert_amount/$c_cur_from->data('cash_exchange'))*$c_cur_to->data('cash_exchange'));
					$exchanger->remove_by_id_array(array($c_cur_from->id() => $convert_amount));
					$exchanger->give_by_id_array(array($c_cur_to->id() => $converted_amount));
 -----[取代為]-----

代碼: 選擇全部

					$convert_amount = floor( $convert_amount * pow(10,$c_cur_from->data('cash_decimals')) ) / pow(10,$c_cur_from->data('cash_decimals'));
					$converted_amount_to = (($convert_amount/$c_cur_from->data('cash_exchange'))*$c_cur_to->data('cash_exchange'));
					$converted_amount_to = floor( $converted_amount_to * pow(10,$c_cur_to->data('cash_decimals')) ) / pow(10,$c_cur_to->data('cash_decimals'));
					$converted_amount_from = (($converted_amount_to/$c_cur_to->data('cash_exchange'))*$c_cur_from->data('cash_exchange'));
					$converted_amount_from = floor( $converted_amount_from * pow(10,$c_cur_from->data('cash_decimals')) ) / pow(10,$c_cur_from->data('cash_decimals'));
					$exchanger->remove_by_id_array(array($c_cur_from->id() => $converted_amount_from));
					$exchanger->give_by_id_array(array($c_cur_to->id() => $converted_amount_to));
 -----[存檔/關閉]-----

*****
我的英文不好\r
並沒去看原作者有沒有比較好處理方法

發表於 : 2005-03-15 20:34
reesion2
剛剛試了一下,果然可以...無限增加貨幣


看了開文大大的文章才知道是計算的錯誤。

我的方法是,1:100的話,
兌換貨幣就要開小數位數2位
1:1000~就要三位
以此類推...
這樣就不會錯了

但是這樣幣值就換有點難看,出現小數點。

發表於 : 2005-03-16 00:58
richer
我的這個方法
應該不會讓幣值變的很難看吧\r

好歹為了這小問題
也花了好多的時間
(幾乎都花在找尋公式上)