第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

為什么這個(gè) PHP 函數(shù)/MySQL 數(shù)據(jù)庫(kù)要四舍五入十進(jìn)制值?

為什么這個(gè) PHP 函數(shù)/MySQL 數(shù)據(jù)庫(kù)要四舍五入十進(jìn)制值?

PHP
湖上湖 2021-11-26 17:49:52
我正在努力處理一些 PHP 代碼,該代碼將商品的價(jià)格插入 MySQL 數(shù)據(jù)庫(kù)。該價(jià)格被插入,但它總是被舍去。例如,如果我插入一個(gè)數(shù)字 9.99,它會(huì)在數(shù)據(jù)庫(kù)中四舍五入為 9.00。我認(rèn)為這是 PHP 代碼的問(wèn)題,因?yàn)槲以?phpMyAdmin 中使用 sql 語(yǔ)句手動(dòng)插入了數(shù)據(jù),并且數(shù)據(jù)沒(méi)有被四舍五入。我曾經(jīng)item_price DECIMAL(7,2) NOT NULL創(chuàng)建過(guò)列,所以它應(yīng)該接受小數(shù)位。我還曾經(jīng)echo檢查過(guò)正確的值是否從 html 表單到達(dá) .php 文件,并顯示了一個(gè)帶小數(shù)點(diǎn)的值。我$total像這樣定義變量:// Is repeated across multiple functions$price = test_input($_POST["price-2"]);$total += $price這是將信息插入數(shù)據(jù)庫(kù)的代碼部分:echo $total; // Returns a decimal value (eg 9.99)$sql = "INSERT INTO purchase_requests (submitted_by, request_type, summary, cost_centre, location, location_details, transport, total_price, approved, approver, paid) VALUES (?,'purchase',?,?,?,?,'false',?,'pending','pending','pending');";$stmt = mysqli_stmt_init($conn);if(!mysqli_stmt_prepare($stmt, $sql)) {  echo "SQL Error";} else {  mysqli_stmt_bind_param($stmt, "issssi", $submitter, $summary, $costCentre,  $location, $locationDetails, $total);  mysqli_stmt_execute($stmt);  mysqli_stmt_close($stmt);  mysqli_close($conn);}誰(shuí)能理解為什么會(huì)發(fā)生這種情況?謝謝!
查看完整描述

1 回答

?
12345678_0001

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超5個(gè)贊

您告訴 PHP 將值保存為整數(shù),使用以下代碼行:

mysqli_stmt_bind_param($stmt, "issssi", $submitter, $summary, $costCentre, $location, $locationDetails, $total);

i代表“整數(shù)”。如果要插入雙精度值,則必須使用d.

在您的情況下,您的線路變?yōu)椋?/p>

mysqli_stmt_bind_param($stmt, "issssd", $submitter, $summary, $costCentre, $location, $locationDetails, $total);



查看完整回答
反對(duì) 回復(fù) 2021-11-26
  • 1 回答
  • 0 關(guān)注
  • 186 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)