|
|
|
ช่วยดูสคริป คำนวณผลรวม มีปัญหาตรงจุดทศนิยมบางตัว เมื่อคำนวณออกมา ผลลัพธ์จะรวนเต็มพรืดไปหมดครับ |
|
|
|
|
|
|
|
คือว่ามันจะมีปัญหาเมื่อเวลามีจุดทศนิยม มารวมกัน แล้วผลรวมมันจะรวนไปเลย รบกวนดูให้ด้วยครับ.Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="th" xml:lang="th">
<head>
<meta http-equiv="content-type" content="text/html; charset=tis-620" />
<title>calculate number</title>
<SCRIPT Language="JavaScript">
//function คำนวณผลรวม
function startCalc(){
interval = setInterval("calc()",1);
}
function calc(){
one = document.enpi.f_gen2_1_1.value.replace(/,/g, '');
two = document.enpi.f_gen2_1_2.value.replace(/,/g, '');
document.enpi.f_gen2.value = ((one * 1) + (two * 1) ).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");;
}
function stopCalc(){
clearInterval(interval);
}
</SCRIPT>
<script type="text/javascript">
//function ใส่จุด Comma ของตัวเลข
function Commas(str)
{
var parts = str.toString().replace("," ,"").split(".");
parts[0] = parts[0].replace("," ,"").replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return parts.join(".");
}
</script>
<form name="enpi" form method="post" action="qa2mail-hotel.php">
<input name="f_gen2_1_1" type="text" class="fill_in" onfocus="startCalc();" onBlur="stopCalc();" size="10" style="text-align: right" onkeyup="this.value = Commas(this.value)" onKeyPress="return bannedKey(event,this.value)"/> A<br />
<input name="f_gen2_1_2" type="text" class="fill_in" onfocus="startCalc();" onBlur="stopCalc();" size="10" style="text-align: right" onkeyup="this.value = Commas(this.value)" onKeyPress="return bannedKey(event,this.value)"/> B<br />
<input name="f_gen2" type=text class="right" style="text-align: right" readonly="readonly"/>
Sum<br />
</form>
</body>
</html>
Tag : PHP, Windows
|
|
|
|
|
|
Date :
2016-07-11 15:04:33 |
By :
npolkhet |
View :
771 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (JavaScript)
<script Language="JavaScript">
function startCalc(){
interval = setInterval("calc()",1);
}
function calc(){
one = document.enpi.f_gen2_1_1.value.replace(/\,/g,"");
two = document.enpi.f_gen2_1_2.value.replace(/\,/g,"");
document.enpi.f_gen2_1_1.value = formatNumber(one);
document.enpi.f_gen2_1_2.value = formatNumber(two);
document.enpi.f_gen2.value = formatNumber((one * 1) + (two * 1));
}
function formatNumber(num) {
return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,")
}
function stopCalc(){
clearInterval(interval);
}
</script>
|
|
|
|
|
Date :
2016-07-11 16:31:46 |
By :
fossil31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|