จำนวนผู้เข้าชม : 695
เราขอแนะนำตัวอย่างการเขียนคำสั่ง Javascript สำหรับการคำนวณตัวเลข โดยไปเราจะใช้เครื่องหมายทางคณิตศาสตร์ต่าง ๆ ในการเขียนโปรแกรมเพื่อคำนวณตัวเลข ได้แก่ การ บวก ลบ คูณ หาร หารเอาเศษ และการยกกำลังตัวเลข จะเขียนยังไง ลองมาอ่านดูคะ
บวก ลบ คูณ หาร หารเอาเศษ และ การยกกำลังตัวเลขด้วยใช้ คำสั่งภาษา Javascript
- เครื่องหมาย + ใช้สำหรับการบวกเลข
let numberA = 150; let numberB = 180; console.info(`numberA + numberB = ${numberA+numberB}`); //ผลลัพธ์ numberA + numberB = 330
- เครื่องหมาย - ใช้สำหรับการลบเลข
let numberA = 180; let numberB = 120; console.info(`numberA - numberB = ${numberA-numberB}`); //ผลลัพธ์ numberA - numberB = 60
- เครื่องหมาย * ใช้สำหรับการคูณเลข
let numberA = 15; let numberB = 25; console.info(`numberA x numberB = ${numberA*numberB}`); //ผลลัพธ์ numberA x numberB = 375
- เครื่องหมาย / ใช้สำหรับการหารเลข
let numberA = 250; let numberB = 25; console.info(`numberA / numberB = ${numberA/numberB}`); //ผลลัพธ์ numberA / numberB = 10
- เครื่องหมาย % ใช้สำหรับการหารเอาเศษ
let numberA = 52; let numberB = 8; console.info(`numberA % numberB = ${numberA%numberB}`); //ผลลัพธ์ numberA % numberB = 4 //คำนวณจาก 8x6 = 48 | 52-48 = 4
- เครื่องหมาย ** ใช้สำหรับการยกกำลังเลข
let numberA = 5; let numberB = 3; console.info(`numberA ** numberB = ${numberA**numberB}`); หรือ console.info(`numberA ** numberB = ${Math.pow(numberA,numberB)}`); //ผลลัพธ์ numberA ** numberB = 125 //Function Math.pow(x,y) ใช้สำหรับการยกกำลัง
บทความอื่น ๆ เกี่ยวกับ Javascript Math คำนวณและแสดงผลตัวเลข
Array
(
[176157542] => Array
(
[post_type] => post
[post_status] => publish
[post__in] => Array
(
[0] => 6584
[1] => 6534
[2] => 6654
)[orderby] => rand
[posts_per_page] => 12
))SELECT SQL_CALC_FOUND_ROWS dprn_posts.ID
FROM dprn_posts
WHERE 1=1 AND dprn_posts.ID IN (6584,6534,6654) AND dprn_posts.post_type = 'post' AND ((dprn_posts.post_status = 'publish'))
ORDER BY RAND()
LIMIT 0, 12
บทความอื่น ๆ ที่เกี่ยวข้องกับ Javascript/jQuery
Array
(
[935968058] => Array
(
[post_type] => post
[post_status] => publish
[post__in] => Array
(
[0] => 8274
[1] => 8234
[2] => 7290
[3] => 7273
[4] => 7111
[5] => 6750
[6] => 6654
[7] => 6632
[8] => 6607
[9] => 6584
[10] => 6534
[11] => 6452
[12] => 6421
[13] => 5940
[14] => 5932
[15] => 5563
[16] => 5504
[17] => 5228
[18] => 5107
)[orderby] => rand
[posts_per_page] => 12
))SELECT SQL_CALC_FOUND_ROWS dprn_posts.ID
FROM dprn_posts
WHERE 1=1 AND dprn_posts.ID IN (8274,8234,7290,7273,7111,6750,6654,6632,6607,6584,6534,6452,6421,5940,5932,5563,5504,5228,5107) AND dprn_posts.post_type = 'post' AND ((dprn_posts.post_status = 'publish'))
ORDER BY RAND()
LIMIT 0, 12
เป็นยังไงกันบ้างคะสำหรับบทความ Javascript คำสั่งสำหรับ บวก ลบ คูณ หาร หารเอาเศษ และ การยกกำลัง ตัวเลข ดูเพลินก็หวังว่าบทความของเราจะเป็นประโยชน์ต่อท่านไม่มากก็น้อย นอกจากนี้ เรายังมีบทความดี ๆ อีกมากมาย คุณสามารถลองคลิกเขาไปอ่านบทความอื่น ๆ ตามลิงค์ด้านล่างได้เลย
เทคนิคอื่นๆ เกี่ยวกับการเขียนโค้ด คลิก
อย่าลืมไปติดตาม Facebook fanpage ของเรา >> Click <<