Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > ของความคิดเห็นเรื่องการปัดทศนิยม 2 ตำแหน่ง บวกคืนไม่เท่ากับ 100 ในการคิดร้อยละหน่อยครับ



 

ของความคิดเห็นเรื่องการปัดทศนิยม 2 ตำแหน่ง บวกคืนไม่เท่ากับ 100 ในการคิดร้อยละหน่อยครับ

 



Topic : 132239



โพสกระทู้ ( 1,994 )
บทความ ( 10 )



สถานะออฟไลน์
Facebook Blogger



จะเห็นว่า หลังจากปัดทศนิยมแล้ว ผลรวมจะหายไปบ้าง 99.99 บางชุดข้อมูลก็เกินเป็น 100.01 บ้าง
ขอแนวทางการคำนวณให้ยอดรวมได้เท่ากับ 100% ทีครับ

การคิดร้อยละ

โค้ดที่ใช้

Code (PHP)
<table id="document_summary" class="table table-bordered table-striped">
					<thead>
						<tr>
							<th class="text-center">ไตรมาสที่</th>
							<th class="text-right">จำนวน (บาท)</th>
							<th class="text-right">ร้อยละ</th>
						</tr>
					</thead>
					<tbody id="tbody_list">
						<?php
							$data_list_term = array ( 1 => 33510723.38, 2 => 18370386.71, 3 => 13147569.72, 4 => 20764823.03 );
							//$data_list_term = array ( 1 => 16384952.27, 2 => 18174658.77, 3 => 16290075.46, 4 => 17268955.96);
							$total_sum = array_sum($data_list_term);
							$total_term = 0;
							$total_percent = 0;
							$total_loop = count($data_list_term);
							$n=0;
							foreach ($data_list_term as $term=>$total)
							{
								$n++;
								$percent = round(($total * 100) / $total_sum, 2);
								
								
								echo '<tr>
									<td class="text-center">'.$term.'</td>
									<td class="text-right">'. number_format($total, 2) .'</td>
									<td class="text-right">'. number_format($percent, 2) .'</td>
								</tr>';
								$total_term += $total;
								$total_percent += $percent;
							}
						?>
						<tr>
							<th class="text-center">รวม</th>
							<th class="text-right"><?php echo number_format($total_term, 2);?></th>
							<th class="text-right"><?php echo number_format($total_percent, 2);?></th>
						</tr>
					</tbody>
				</table>




Tag : PHP









ประวัติการแก้ไข
2018-10-06 08:48:21
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2018-10-05 12:26:15 By : {Cyberman} View : 6435 Reply : 16
 

 

No. 1



โพสกระทู้ ( 157 )
บทความ ( 0 )



สถานะออฟไลน์


ลองนะครับ
$percent = ($total * 100) / $total_sum;


เพราะใน td ก็มีคำสั่ง number_format อยู่แล้วครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-10-05 13:36:34 By : Jatmentz
 


 

No. 2



โพสกระทู้ ( 1,994 )
บทความ ( 10 )



สถานะออฟไลน์
Facebook Blogger

การคิดร้อยละ

ปัญหาที่พบคือ เมื่อเอารายการแต่ละแถวมารวมกัน มันไม่ได้ 100% ครับ

ที่ใช้

$percent = round(($total * 100) / $total_sum, 2);

เพราะว่าจะได้เห็นว่า ยอดรวมกับยอดที่แสดงตรงกันหรือไม่ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-10-05 13:44:21 By : {Cyberman}
 

 

No. 3



โพสกระทู้ ( 5,105 )
บทความ ( 4 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์


https://stackoverflow.com/questions/11114861/php-adding-2-decimal-points-numbers-money-gives-wrong-results-in-total-amount

เขาตอบว่า Indeed, floating point numbers are not precise. Either calculate in cent (multiply by 100 and calculate in integers), or calculate in strings using BC Math.

ผมก็ไม่เข้าใจว่าคืออะไร ลองไล่ดูนะครับ http://php.net/bcmath

ลองเล่น round ดูครับว่าผลรวมมันจะออกมา 100 ไหม

echo round(3.4);         // 3
echo round(3.5);         // 4
echo round(3.6);         // 4
echo round(3.6, 0);      // 4
echo round(1.95583, 2);  // 1.96
echo round(1241757, -3); // 1242000
echo round(5.045, 2);    // 5.05
echo round(5.055, 2);    // 5.06

echo round(9.5, 0, PHP_ROUND_HALF_UP);   // 10
echo round(9.5, 0, PHP_ROUND_HALF_DOWN); // 9
echo round(9.5, 0, PHP_ROUND_HALF_EVEN); // 10
echo round(9.5, 0, PHP_ROUND_HALF_ODD);  // 9

echo round(8.5, 0, PHP_ROUND_HALF_UP);   // 9
echo round(8.5, 0, PHP_ROUND_HALF_DOWN); // 8
echo round(8.5, 0, PHP_ROUND_HALF_EVEN); // 8
echo round(8.5, 0, PHP_ROUND_HALF_ODD);  // 9



ตย.นี้ก็ดีนะ
https://stackoverflow.com/questions/13483430/how-to-make-rounded-percentages-add-up-to-100

คำตอบของอันนี้บอกว่าทำไมไม่ได้ 100%
https://stackoverflow.com/questions/21581341/how-to-round-half-on-a-set-of-numbers-which-sum-to-100

อ่ะ!! อันสุดท้าย เขายืนยันว่า 100% แน่นอน
https://revs.runtime-revolution.com/getting-100-with-rounded-percentages-273ffa70252b


ประวัติการแก้ไข
2018-10-05 14:02:13
2018-10-05 14:09:35
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-10-05 13:59:23 By : apisitp
 


 

No. 4



โพสกระทู้ ( 9,544 )
บทความ ( 2 )



สถานะออฟไลน์


ตรวจสอบข้อมูล ถ้า เกิน 100.00 เช่น 100.01 ให้ลบรายการสุดท้าย ออก 0.01
ทำนองเดียวกัน กับ ถ้าขาด ก็บวกเพิ่ม 0.01
โดนการ ทำข้อมูล ให้เรียบร้อยก่อน แสดงผล เอาผลลัพธ์ ใส่ใน array ไว้ก่อน

มันมีโอกาสเพี้ยน ครึ่งๆ

ปล. ถ้าต้องการละเอียดจริงๆ ว่าควรจะตัดยอด หรือเพิ่ม รายการไหน
ก็ให้เอาส่วนที่ตัด ออกมาคำนวณด้วย
รายการไหน ที่มันปัดขึ้นใกล้ 0.005 ก็ลบอันนั้น
หรือปัดลง ใกล้ 0.005 มากที่สุดก็บวกอันนั้น
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-10-05 15:01:53 By : Chaidhanan
 


 

No. 5



โพสกระทู้ ( 157 )
บทความ ( 0 )



สถานะออฟไลน์


ลองดูแบบนี้ไหมครับ round(num, 1)
eg
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-10-05 15:35:37 By : Jatmentz
 


 

No. 6



โพสกระทู้ ( 1,994 )
บทความ ( 10 )



สถานะออฟไลน์
Facebook Blogger

ตอบความคิดเห็นที่ : 3 เขียนโดย : apisitp เมื่อวันที่ 2018-10-05 13:59:23
รายละเอียดของการตอบ ::
ขอบคุณครับ จะลองดูครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-10-05 20:47:57 By : {Cyberman}
 


 

No. 7



โพสกระทู้ ( 1,994 )
บทความ ( 10 )



สถานะออฟไลน์
Facebook Blogger

ตอบความคิดเห็นที่ : 4 เขียนโดย : Chaidhanan เมื่อวันที่ 2018-10-05 15:01:53
รายละเอียดของการตอบ ::
ขอยคุณสำหรับวิธีการครับ ถ้าไม่มีฟังก์ชั่นที่ใช้ได้คงจะต้องใช้วิธีนี้จริงๆครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-10-05 21:02:01 By : {Cyberman}
 


 

No. 8



โพสกระทู้ ( 1,994 )
บทความ ( 10 )



สถานะออฟไลน์
Facebook Blogger

ตอบความคิดเห็นที่ : 5 เขียนโดย : Jatmentz เมื่อวันที่ 2018-10-05 15:35:37
รายละเอียดของการตอบ ::
วิธีนี้คงไม่ได้ครับ เพราะต้องใช้ 2 หลักครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-10-05 21:03:26 By : {Cyberman}
 


 

No. 9



โพสกระทู้ ( 9 )
บทความ ( 0 )



สถานะออฟไลน์


การกำหนดจุดทศนิยม มีคำสั่งให้ใช้หลากหลายครับ

เราต้องเลือกคำสั่งมาใช้ให้ตรงกับวัตถุประสงค์ของงานของเรา

ที่สำคัญเราต้องชัดเจน 2 เรื่อง

1. ตัดสินใจให้ชัดเจนว่าข้อมูลที่นำเข้ามาจะมีจุดทศนิยมหรือไม่ ปัดขึ้นหรือปัดลง

2. การคำนวณร้อยละ จะต้องเทียบกับฐาน ให้ชัดเจน เมื่อเทียบกับฐานชัดเจนแล้ว ตัวแปรนำเข้าจะต้องไม่เกินฐาน

กรณีนี้ เมื่อคำนวณออกมาแล้วเกิน 100% แสดงว่าข้อมูลที่นำเข้าเกินตั้งแต่ต้น

การที่เราจะเขียน code เพื่อให้ส่วนที่เกินมีค่ากลับมาเท่ากับ 100% ผมมองว่าเป็นเรื่องที่ไม่ควรครับ

เพราะข้อมูลที่นำเข้าแต่ละชุดมีการผันแปรไม่ตรงกัน

ดังนั้นควรกรองตั้งแต่ต้นทางว่าข้อมูลดิบจะต้องไม่เกินค่าสูงสุดครับ

ตัวอย่าง

มีสินค้า 100 ชิ้น
นาย ก ขายได้ 20 ชิ้น คิดเป็น 20%
นาย ข ขายได้ 30 ชิ้น คิดเป็น 30%
นาย ค ขายได้ 50 ชิ้น คิดเป็น 50%
รวมทั้งสิ้น ขายได้ 100 ชิ้น คิดเป็น 100%

แต่จากข้อมูลข้างต้นจะกลายเป็นประมาณว่า
มีสินค้า 100 ชิ้น
นาย ก ขายได้ 20.1 ชิ้น คิดเป็น 20.1%
นาย ข ขายได้ 30.4 ชิ้น คิดเป็น 30.4%
นาย ค ขายได้ 50.4 ชิ้น คิดเป็น 50.4%
รวมทั้งสิ้นขายไป 100.9 ชิ้น คิดเป็น 100.9%
ประมาณนี้ครับ

สอบถามเพิ่มเติมได้ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-10-05 21:40:30 By : djunghoo
 


 

No. 10



โพสกระทู้ ( 1,994 )
บทความ ( 10 )



สถานะออฟไลน์
Facebook Blogger

ตอบความคิดเห็นที่ : 9 เขียนโดย : djunghoo เมื่อวันที่ 2018-10-05 21:40:30
รายละเอียดของการตอบ ::
โค้ดด้านบนนั้นคือข้อมูลจริงเลยครับ ไม่ได้ดัดแปลงอะไรใดๆ หาร้อยละออกมาด้วยสูตร PHP ทั้ง PHP_ROUND_HALF_EVEN และ PHP_ROUND_HALF_ODD บวกคืนตามภาพที่เห็น ไม่ได้ครบร้อยครับ


ปัญหาที่เจอก็คือ มันปัดถูกหมดแล้วตามรูป ตามหลักการ
แต่พอเอาเฉพาะตัวเลข 2 หลักที่ปัดแล้ว มากดเครื่องคิดเลข (บัญชีส่วนใหญ่เขาจะกดเครื่องคิดเลขครับ)
เพื่อตรวจสอบความถูกต้อง กลับได้ไม่ครบ 100% ซะงั้น


คิดร้อยละกลับคืนไม่ได้


ประวัติการแก้ไข
2018-10-06 07:12:58
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-10-06 07:05:18 By : {Cyberman}
 


 

No. 11



โพสกระทู้ ( 1,994 )
บทความ ( 10 )



สถานะออฟไลน์
Facebook Blogger

ลองทั้ง PHP_ROUND_HALF_EVEN และ PHP_ROUND_HALF_ODD ก็ยังไม่ได้ครับ

ไม่ลงตัว


ลองเอาโค้ดไปรันได้ที่ http:// https://phpfiddle.org/


Code (PHP)
<style>table table{
    border-spacing: 5px;
    border-collapse: collapse;
    }    
    table table td, table table th{
        border: 1px solid black;
    }
</style>
<table border="1" cellpadding="10">
    <tr>
        <td>ปัดทศนิยม 2 ตำแหน่ง</td>
        <td>ปัดทศนิย 2 ตำแหน่ง ด้วย PHP_ROUND_HALF_EVEN</td>
        <td>ปัดทศนิย 2 ตำแหน่ง ด้วย PHP_ROUND_HALF_ODD</td>
    </tr>
<tr>
<td>
<table id="document_summary" class="table table-bordered table-striped">
    <thead>
        <tr>
            <th class="text-center">ไตรมาสที่</th>
            <th class="text-right">จำนวน (บาท)</th>
            <th class="text-right">ร้อยละ</th>
        </tr>
    </thead>
					<tbody id="tbody_list">
						<?php
							$data_list_term = array ( 1 => 33510723.38, 2 => 18370386.71, 3 => 13147569.72, 4 => 20764823.03 );
							$total_sum = array_sum($data_list_term);
							$total_term = 0;
							$total_percent = 0;
							$total_loop = count($data_list_term);
							$n=0;
							foreach ($data_list_term as $term=>$total)
							{
								$n++;
								$percent = round(($total * 100) / $total_sum, 2);
								
								
								echo '<tr>
									<td class="text-center">'.$term.'</td>
									<td class="text-right">'. number_format($total, 2) .'</td>
									<td class="text-right">'. number_format($percent, 2) .'</td>
								</tr>';
								$total_term += $total;
								$total_percent += $percent;
							}
						?>
						<tr>
							<th class="text-center">รวม</th>
							<th class="text-right"><?php echo number_format($total_term, 2);?></th>
							<th class="text-right"><?php echo number_format($total_percent, 2);?></th>
						</tr>
					</tbody>
				</table>
<br/>
<table id="document_summary" class="table table-bordered table-striped">
					<thead>
						<tr>
							<th class="text-center">ไตรมาสที่</th>
							<th class="text-right">จำนวน (บาท)</th>
							<th class="text-right">ร้อยละ</th>
						</tr>
					</thead>
					<tbody id="tbody_list">
						<?php
							$data_list_term = array ( 1 => 16384952.27, 2 => 18174658.77, 3 => 16290075.46, 4 => 17268955.96);
							$total_sum = array_sum($data_list_term);
							$total_term = 0;
							$total_percent = 0;
							$total_loop = count($data_list_term);
							$n=0;
							foreach ($data_list_term as $term=>$total)
							{
								$n++;
								$percent = round(($total * 100) / $total_sum, 2);
								
								
								echo '<tr>
									<td class="text-center">'.$term.'</td>
									<td class="text-right">'. number_format($total, 2) .'</td>
									<td class="text-right">'. number_format($percent, 2) .'</td>
								</tr>';
								$total_term += $total;
								$total_percent += $percent;
							}
						?>
						<tr>
							<th class="text-center">รวม</th>
							<th class="text-right"><?php echo number_format($total_term, 2);?></th>
							<th class="text-right"><?php echo number_format($total_percent, 2);?></th>
						</tr>
					</tbody>
				</table>


</td>
<td>
<table id="document_summary" class="table table-bordered table-striped">
					<thead>
						<tr>
							<th class="text-center">ไตรมาสที่</th>
							<th class="text-right">จำนวน (บาท)</th>
                            <th class="text-right">ร้อยละ</th>
							<th class="text-right">ร้อยละ</th>
						</tr>
					</thead>
					<tbody id="tbody_list">
						<?php
							$data_list_term = array ( 1 => 33510723.38, 2 => 18370386.71, 3 => 13147569.72, 4 => 20764823.03 );
							$total_sum = array_sum($data_list_term);
							$total_term = 0;
							$total_percent = 0;
							$total_loop = count($data_list_term);
							$n=0;
                            $total_percent_4 = 0;
							foreach ($data_list_term as $term=>$total)
							{
								$n++;
                                $percent_4 = ($total * 100) / $total_sum;
                                $total_percent_4 += $percent_4;
								$percent = round(($total * 100) / $total_sum, 2, PHP_ROUND_HALF_EVEN);
								
								echo '<tr>
									<td class="text-center">'.$term.'</td>
									<td class="text-right">'. number_format($total, 2) .'</td>
                                    <td class="text-right">'. number_format($percent_4, 4) .'</td>
									<td class="text-right">'. number_format($percent, 2) .'</td>
								</tr>';
                                
								$total_term += $total;
								$total_percent += $percent;
							}
						?>
						<tr>
							<th class="text-center">รวม</th>
							<th class="text-right"><?php echo number_format($total_term, 2);?></th>
                            <th class="text-right"><?php echo number_format($total_percent_4, 2);?></th>
							<th class="text-right"><?php echo number_format($total_percent, 2);?></th>
						</tr>
					</tbody>
				</table>
<br/>
<table id="document_summary" class="table table-bordered table-striped">
					<thead>
						<tr>
							<th class="text-center">ไตรมาสที่</th>
							<th class="text-right">จำนวน (บาท)</th>
							<th class="text-right">ร้อยละ</th>
                            <th class="text-right">ร้อยละ</th>
						</tr>
					</thead>
					<tbody id="tbody_list">
						<?php
							$data_list_term = array ( 1 => 16384952.27, 2 => 18174658.77, 3 => 16290075.46, 4 => 17268955.96);
							$total_sum = array_sum($data_list_term);
							$total_term = 0;
							$total_percent = 0;
							$total_loop = count($data_list_term);
							$n=0;
                            $total_percent_4 = 0;
							foreach ($data_list_term as $term=>$total)
							{
								$n++;
                                $percent_4 = ($total * 100) / $total_sum;
                                $total_percent_4 += $percent_4;
								$percent = round(($total * 100) / $total_sum, 2, PHP_ROUND_HALF_EVEN);
								
								
								echo '<tr>
									<td class="text-center">'.$term.'</td>
									<td class="text-right">'. number_format($total, 2) .'</td>
                                    <td class="text-right">'. number_format($percent_4, 4) .'</td>
									<td class="text-right">'. number_format($percent, 2) .'</td>
								</tr>';
								$total_term += $total;
								$total_percent += $percent;
							}
						?>
						<tr>
							<th class="text-center">รวม</th>
							<th class="text-right"><?php echo number_format($total_term, 2);?></th>
                            <th class="text-right"><?php echo number_format($total_percent_4, 2);?></th>
							<th class="text-right"><?php echo number_format($total_percent, 2);?></th>
						</tr>
					</tbody>
				</table>

</td>
    <td>
<table id="document_summary" class="table table-bordered table-striped">
					<thead>
						<tr>
							<th class="text-center">ไตรมาสที่</th>
							<th class="text-right">จำนวน (บาท)</th>
							<th class="text-right">ร้อยละ</th>
                            <th class="text-right">ร้อยละ</th>
						</tr>
					</thead>
					<tbody id="tbody_list">
						<?php
							$data_list_term = array ( 1 => 33510723.38, 2 => 18370386.71, 3 => 13147569.72, 4 => 20764823.03 );
							$total_sum = array_sum($data_list_term);
							$total_term = 0;
							$total_percent = 0;
							$total_loop = count($data_list_term);
							$n=0;
                            $total_percent_4 = 0;
							foreach ($data_list_term as $term=>$total)
							{
								$n++;
                                $percent_4 = ($total * 100) / $total_sum;
                                $total_percent_4 += $percent_4;
								$percent = round(($total * 100) / $total_sum, 2, PHP_ROUND_HALF_ODD);
								
								echo '<tr>
									<td class="text-center">'.$term.'</td>
									<td class="text-right">'. number_format($total, 2) .'</td>
                                    <td class="text-right">'. number_format($percent_4, 4) .'</td>
									<td class="text-right">'. number_format($percent, 2) .'</td>
								</tr>';
                                
								$total_term += $total;
								$total_percent += $percent;
							}
						?>
						<tr>
							<th class="text-center">รวม</th>
							<th class="text-right"><?php echo number_format($total_term, 2);?></th>
                            <th class="text-right"><?php echo number_format($total_percent_4, 2);?></th>
							<th class="text-right"><?php echo number_format($total_percent, 2);?></th>
						</tr>
					</tbody>
				</table>
<br/>
<table id="document_summary" class="table table-bordered table-striped">
					<thead>
						<tr>
							<th class="text-center">ไตรมาสที่</th>
							<th class="text-right">จำนวน (บาท)</th>
							<th class="text-right">ร้อยละ</th>
                            <th class="text-right">ร้อยละ</th>
						</tr>
					</thead>
					<tbody id="tbody_list">
						<?php
							$data_list_term = array ( 1 => 16384952.27, 2 => 18174658.77, 3 => 16290075.46, 4 => 17268955.96);
							$total_sum = array_sum($data_list_term);
							$total_term = 0;
							$total_percent = 0;
							$total_loop = count($data_list_term);
							$n=0;
                            $total_percent_4 = 0;
							foreach ($data_list_term as $term=>$total)
							{
								$n++;
                                $percent_4 = ($total * 100) / $total_sum;
                                $total_percent_4 += $percent_4;
								$percent = round(($total * 100) / $total_sum, 2, PHP_ROUND_HALF_ODD);
								
								
								echo '<tr>
									<td class="text-center">'.$term.'</td>
									<td class="text-right">'. number_format($total, 2) .'</td>
                                    <td class="text-right">'. number_format($percent_4, 4) .'</td>
									<td class="text-right">'. number_format($percent, 2) .'</td>
								</tr>';
								$total_term += $total;
								$total_percent += $percent;
							}
						?>
						<tr>
							<th class="text-center">รวม</th>
							<th class="text-right"><?php echo number_format($total_term, 2);?></th>
                            <th class="text-right"><?php echo number_format($total_percent_4, 2);?></th>
							<th class="text-right"><?php echo number_format($total_percent, 2);?></th>
						</tr>
					</tbody>
				</table>

</td>
</tr>
</table>

</table>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-10-06 08:00:39 By : {Cyberman}
 


 

No. 12



โพสกระทู้ ( 1,994 )
บทความ ( 10 )



สถานะออฟไลน์
Facebook Blogger

ตอบความคิดเห็นที่ : 4 เขียนโดย : Chaidhanan เมื่อวันที่ 2018-10-05 15:01:53
รายละเอียดของการตอบ ::
คิดว่าสุดท้าย คงต้องใช้วิธีของคุณ Chaidhanan แล้วครับ



ปัญหาจากที่อื่นๆ
ทำให้ร้อยละรวมได้100 (Excel)
https://www.snasui.com/viewtopic.php?t=9600


ประวัติการแก้ไข
2018-10-06 08:28:28
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-10-06 08:16:53 By : {Cyberman}
 


 

No. 13



โพสกระทู้ ( 9 )
บทความ ( 0 )



สถานะออฟไลน์


อธิบายเพิ่มเติมครับ

ใน excel เราสามารถกำหนดให้แสดงจำนวนจุดทศนิยมได้

ซึ่งหากข้อมูล ที่ได้มีจำนวน ทศนิยม 3 ตำแหน่ง แต่เราต้องการให้แสดงเพียง 2 ตำแหน่ง

เราสามารถที่จะระบุได้ว่า จะปัดขึ้นหรือปัดลง แล้วให้แสดงให้เราเป็นเช่น

2.453 เมื่อแสดงเป็น 2 ตำแหน่ง จะได้ 2.45 ให้เราเห็น แต่จริง ๆ แล้วค่าของ cell นี้ก็ยังเป็น 2.453 เหมือนเดิม
และเมื่อทุกแถวดำเนินการในลักษณะเดียวกันนี้ ค่าที่แสดงจะเป็น 2 ตำแหน่ง แต่ ค่าจริง ๆ ก็ยังเป็นค่าก่อนแสดง 2 ตำแหน่ง อยู่ดี
เมื่อนำมาคำนวณร้อยละ ก็จะได้ 100 %

ถ้าเราใช้วิธีตัดอักษร ซึ่งต่างจากการปัดขึ้นปัดลง คือ จาก 3 ตำแหน่ง ตัดเหลือ 2 ตำแหน่ง จะทำให้ค่าแท้จริงเปลี่ยนครับ

ยกตัวอย่างเดิม

2.453 เมื่อตัดตัวอักษร เป็น 2 ตำแหน่ง จะได้ 2.45 ซึ่งจะได้ค่าเป็น 2.45 ซึ่งจริง ๆ นั้นค่าขาดไป 0.003

ถ้าทำแบบนี้ทุก ๆ แถว ค่าจะขาดไปเรือย ๆ ซึ่งทำยังไงก็ไม่สามารถรวมเป็น 100% ได้ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-10-06 16:23:52 By : djunghoo
 


 

No. 14



โพสกระทู้ ( 9,544 )
บทความ ( 2 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 12 เขียนโดย : {Cyberman} เมื่อวันที่ 2018-10-06 08:16:53
รายละเอียดของการตอบ ::
ตอนแรกจะเข้ามาบอกว่าต้องทำแบบที่ผมบอก แต่เห็นว่าจะลองค้น ก็เลยปล่อย เพราะยังไงก็ต้องได้ประโยชน์ไม่ทางใดก็ทางหนึ่ง
เพราะเมื่อก่อนผมก็เคยลองหาแบบคุณนี่แหล่ะ มันได้ประโยชน์มาก จากการค้นหาด้วยตัวเอง อะไรที่ไม่เคยรู้ก็ได้รู้เพิ่มขึ้น


สรุปง่ายๆ ข้อมูลที่ดัดแปลงแล้ว ผลรวมย่อมไม่เท่ากับผลรวมของข้อมูลจริง นอกจากฟลุ๊ค
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-10-06 20:01:40 By : Chaidhanan
 


 

No. 15



โพสกระทู้ ( 1,994 )
บทความ ( 10 )



สถานะออฟไลน์
Facebook Blogger

ตอบความคิดเห็นที่ : 13 เขียนโดย : djunghoo เมื่อวันที่ 2018-10-06 16:23:52
รายละเอียดของการตอบ ::
ขอบคุณสำหรับความคิดเห็นครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-10-06 22:23:41 By : {Cyberman}
 


 

No. 16



โพสกระทู้ ( 1,994 )
บทความ ( 10 )



สถานะออฟไลน์
Facebook Blogger

ตอบความคิดเห็นที่ : 14 เขียนโดย : Chaidhanan เมื่อวันที่ 2018-10-06 20:01:40
รายละเอียดของการตอบ ::
ขอบคุณสำหรับแนวคิดครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-10-06 22:25:01 By : {Cyberman}
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ของความคิดเห็นเรื่องการปัดทศนิยม 2 ตำแหน่ง บวกคืนไม่เท่ากับ 100 ในการคิดร้อยละหน่อยครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่