หนึ่งในปัญหาคลาสิก เวลาเขียนโปรแกรมที่ทุกคนต้องเจอเลย
ก็คือการบวกลบเลขทศนิยมในภาษาโปรแกรม ของบางภาษา นี้แหละ
เช่น JavaScript, Python, Perl, C#, C, C++, Java, PHP, Fortran
(และอื่นๆ อีกหลายภาษาที่ไม่ได้กล่าวถึง)
.
หลายครั้งที่มันอาจเพี้ยนได้ เช่น
👉 0.1+0.2 ไม่ได้เท่ากับ 0.3
แต่ได้เป็น 0.30000000000000004
.
👉 หรือ 0.1 บวกกัน 10 ครั้ง ก็ไม่ได้เป็น 1
แต่ได้เป็น 0.9999999999999999
.
คนเขียนโปรแกรมเจอแบบนี้เข้าไป
ก็เหมือนมวยโดนหมัดน๊อคมึนงงในดงโค้ด
:
:
แต่ใช่ว่ามันจะเพี้ยนทุกครั้ง ซะเมื่อไร เช่น
0.5+0.5 = 1 (ถูกต้องเป๊ะ)
0.2+0.3 = 0.5 (บังเอิญไม่เพี้ยน)
.
สำหรับ กรณี 0.2 กับ 0.3 มันถูกตัดเศษเหลือเป็น
0.2000000000000000111022302462515654042363166809082031250
กับ
0.2999999999999999888977697537484345957636833190917968750
พอบวกกันจึงได้ 0.5 พอดี แบบฟลุ๊คๆๆ ซึ่งไม่ควรทำได้
(ตรงสอบดูได้ 0.2+0.3 == 0.5 ได้ค่าออกมาเป็น true)
:
:
สาเหตุที่เป็นเช่นนี้
ก็เพราะว่าคอมพิวเตอร์มันรู้จักแต่ เลขฐาน2 อะนะ
ต่อให้เราเขียนโค้ดใช้เลขฐาน10 ก็ตาม
สุดท้ายเวลาโค้ดมันถูกรัน ก็จะกลายเป็นเลขฐาน 2 อยู่ดี
.
😨 แล้วก็เป็นความซวยที่จะมาเยือนคนเขียนโปรแกรม
เพราะเวลาแปลงเลขฐาน10 ไปเป็นเลขฐาน 2
บางกรณีมันแปลงแล้ว ดันได้ตัวเลขที่ไม่รู้จบเสียด้วยซิ
จึงทำให้การเก็บทศนิยมผิดเพี้ยนไปได้
.
สำหรับรูปแบบการจัดเก็บเลขทศนิยม ในหลายภาษา
เขาจะนิยมใช้มาตรฐาน IEEE-754 floating point
เช่น 0.1 จะถูกมองว่าคือ 1/10
.
เมื่อเก็บเป็นเลขทศนิยมฐานสอง
ตามมาตรฐาน IEEE-754 floating point จะได้เป็น
0.0001100110011001100110011001100110011001100110011...
เป็นทศนิยมไม่รู้จบในรูปเลขฐานสอง ....นี้คือสิ่งที่คอมมองเห็น
.
พอคอมแปลงกลับมาเป็นทศนิยม เพื่อให้มนุษย์โลกอ่านเข้าใจ
ในรูปฐาน 10 ก็จะได้เป็น
0.1000000000000000055511151231257827021181583404541015625
ทว่าคอมมันจะตัดให้เหลือแค่ 0.1 (คนจึงเห็นแค่นี้)
:
🤔 ซึ่งความเพื้ยนแบบนี้
แน่นอนทำให้เกิดบั๊กเวลาคำนวณตัวเลข
- ยิ่งงานต้องการคำตอบที่ละเอียดมาก เช่น งานธนาคาร ก็จะประสบปัญหา เป็นต้น
- หรือเวลานำไปใช้ในเงื่อนไขเปรียบเทียบพวก if, while ฯลฯ ก็อาจมีบั๊กเกิดขึ้นได้ เป็นต้น
.
😀 แต่ไม่ต้องห่วง ในหลายๆ ภาษาเขาจะมีวิธีแก้ปัญหานี้อยู่ครับ
ป้องกันการคำนวณตัวเลข ไม่ให้คลาดเคลื่อน เช่น
- ใน Java ก็จะมีคลาส BigDecimal เอาไว้บวกลบคูณหาร สำหรับเลขทศนิยมโดยเฉพาะ
- ใน Python ก็จะมีคลาสคล้ายๆ กัน เช่น Decimal
- ส่วนใน JavaScript อาจใช้ไลบรารี่ ซึ่งมีให้เลือกเยอะเช่น
https://github.com/MikeMcl/decimal.js/
https://github.com/MikeMcl/bignumber.js/
https://github.com/MikeMcl/big.js/
- ภาษาอื่นที่เหลือลองไปศึกษาเองดูนะครับ
.
.
เรื่องบวกลบคูณหาร เลขทศนิยม ถือเป็นเรื่องสำคัญที่ไม่ควรมองข้าม
โดยส่วนตัวก็เคยเจอความเผลอเรอตรงนี้
ในระดับโปรเจคระดับธนาคาร ก็เคยพลาดมาแล้ว
สุดท้ายต้องมาไล่นั่งแก้โค้ดหลายบรรทัด
เสียเวลานั่งไล่ test ใหม่อีกรอบอีก
.
หมายเหตุเห็นคอมเมนต์สงสัยว่า
PHP กับ C# รอดชะตากรรมเดียวกันไหม ?
ก็บอกว่าไม่รอดครับ
.
// ลองดูตัวอย่างโค้ด C#
Console.WriteLine( ((0.1+0.2) == 0.3)); // False
Console.WriteLine( ((0.1+0.2) == 0.30000000000000004)); // True
// ลองดูตัวอย่างโค้ด PHP
echo number_format(0.1+0.2 , 17);
.
++++++
เขียนโดย โปรแกรมเมอร์ไทย thai programmer
อ่านเรื่อง IEEE-754 floating point ได้ที่
https://th.wikipedia.org/wiki/จำนวนจุดลอยตัว
One of those classic problems, programming that everyone needs to encounter.
It's positive to delete decimal numbers in some language.
เช่น JavaScript, Python, Perl, C#, C, C++, Java, PHP, Fortran
(and many other languages not mentioned)
.
Many times it can be crazy like
👉 0.1 + 0.2 is not equal to 0.3
But I got to be 0.30000000000000004
.
👉 or 0.1 plus 10 times. It's not 1
But I got to be 0.9999999999999999
.
The Programmer found this.
It's like boxing. I got hit by a punch. I'm confused in dong code.
:
:
But it's not that it's crazy every time like
0.5 + 0.5 = 1 (exactly correct)
0.2 + 0.3 = 0.5 (accidentally not crazy)
.
For Case 0.2 and 0.3 it was cut down.
0.2000000000000000111022302462515654042363166809082031250
With the.
0.2999999999999999888977697537484345957636833190917968750
When we are positive, we get 0.5 fit like fluke which you shouldn't be able to do.
(I can watch the exam. 0.2 + 0.3 == 0.5 get the value to be true)
:
:
The cause is like this
Because computers only know the base number 2
Even if we write code, use base number 10
In the end, when the code is run, it will become base number 2 anyway.
.
😨 and it's bad luck to visit the programmer.
Because time to convert base number 10 to base number 2
In some cases, it's converted and I get the number that I don't end.
So it makes the decimal picking wrong.
.
For the decimal number storage in multiple languages
He will be popular with IEEE-754 floating point standards
For example, 0.1 will be seen as 1/10
.
When keeping it as a decimal number, base two.
According to IEEE-754 floating point standards.
0.0001100110011001100110011001100110011001100110011...
It's a decimal. I don't finish in the second base picture.... this is what the computer can see.
.
When the computer converts back to decimal so that the world can read and understand.
In the picture of base 10 will be.
0.1000000000000000055511151231257827021181583404541015625
But the computer will cut to only 0.1 (so people see this)
:
🤔 this kind of being
Sure. It makes cuddle times to calculate numbers.
- the more jobs need detailed answers such as banking work, there will be problems, etc.
- or time to use in comparison terms. If, while etc. There may be cuddle baht.
.
😀 but don't worry. in many languages, there will be a solution to this problem.
Prevent calculation of numbers from inaccurate such as
- in Java, there will be bigdecimal class to delete multiplication for decimal numbers especially.
- in python, there will be similar classes such as decimal.
- Javascript may use a lot of libraries to choose from.
https://github.com/MikeMcl/decimal.js/
https://github.com/MikeMcl/bignumber.js/
https://github.com/MikeMcl/big.js/
- the rest of the other languages, try to study it yourself.
.
.
It's important to delete multiplication, divide the decimal numbers. It's important that you should not overlook.
Personally, I have met a burp here.
At Project Level, bank level has been missed.
Finally, I have to sit and fix many lines of code.
Wasting time to sit and chase the test again.
.
Note that I see the comments. I wonder if
Php and c #survive the same fate?
I said I wouldn't survive.
.
// check out the code C Sample #
Console.WriteLine( ((0.1+0.2) == 0.3)); // False
Console.WriteLine( ((0.1+0.2) == 0.30000000000000004)); // True
// check out the sample code php
echo number_format(0.1+0.2 , 17);
.
++++++
Written by Thai Programmer Thai programmer
Read about IEEE-754 floating point at
https://th.wikipedia.org/wiki/จำนวนจุดลอยตัวTranslated
同時也有39部Youtube影片,追蹤數超過12萬的網紅prasertcbs,也在其Youtube影片中提到,Anaconda Python เป็น Python ที่ได้รับความนิยมเป็นอย่างมากในหมู่นักพัฒนาโปรแกรม รวมถึงผู้สนใจด้านวิทยาศาสตร์ข้อมูล (Data Science) เพราะติดตั้งได้ง่าย ร...
run python 在 BorntoDev Facebook 八卦
🤣 วันแรก ๆ ที่แอดได้เรียนทั้ง 2 ภาษานี้เกือบสิบปีที่แล้ว จำได้ว่างงจัด ๆ ว่าทำไมคำสั่งเราก็ไม่ได้มีท่าอะไรแปลกประหลาด แต่มัน Run ไม่ได้เฉย ..
.
"สรุปคือ อ๋ออ ลืมไปว่า Python มันไม่มี การเติม ++ หลังตัวแปร 55"
.
#BorntoDev - 🦖 Coding Academy ให้การพัฒนาเทคโนโลยีเป็นเรื่องง่ายสำหรับทุกคน
run python 在 Bà Dì Nulo Facebook 八卦
#nulo_career
Bi, Ba cái gương và thủy tinh cầu
Bi là gì?
dì mới thấy 1 job ở SG khá hay đang tuyển dành cho fresh nên dì muốn share cho các cháu thích làm việc với data, dân ngành nào cũng đâm sang được miễn thích data, tools và luôn thích tự học.
Bi là Business Intelligence
Ba là Business Analytics
2 bạn này là 2 môn phái giúp cho doanh nghiệp đưa ra 1 quyết định trọng đại (Decision making)
BI BA khác nhau chứ
BI là tạo ra một tấm gương từ dữ liệu từ 30 giây cho đến rất nhiều năm trước để doanh nghiệp nhìn vô xem lại cái nết ăn ở, tình hình kinh doanh vừa qua của mình để cải thiện sửa đổi
BA là tạo ra quả cầu thủy tinh cho thấy tương lai- từ data của thị trường và doanh nghiệp, để mí bác lãnh đạo hiểu và dự đoán những thứ sắp xảy ra vd như dự định market entrance- thâm nhập và làm ăn ở 1 thị trường mới chẳng hạn,
Người Bi và Ba kiểu gì cũng phải làm lấn sân nhau 1 xíu để có kiến thức kỹ năng toàn diện hơn
tạm vậy đã, cho các cháu biết và phân biệt 2 job tưởng là 1 mà là 2 này, khi nào rảnh dì viết thêm, các cháu có thể tự tìm hiểu thêm nhe
Bên dưới là job đang tuyển cho fresh, JD điển hình cho BI
Intrepid Vietnam is looking for
Junior BI Analyst (8-10 mil experience based)
Deadline for application: 26/2/2020
The role:
We are looking for a generalist, who is eager to learn and has an eye for detail. As a Junior BI Analyst, you will be using different tools to
- Develop and automate internal & external reports
Build dashboards to visualize quantitative information
- Maintain database and other documents
- Fulfill ad-hoc requests
Who we look for – the ideal profile:
- Intermediate English and above
- From 6 months of experience in Ecommerce or in a data-driven position of other industries.
- Advanced Excel and Google sheet is a must.
- Strong logical thinking and problem-solving skills is a must.
- Good communication & ability to probe for users’ data needs.
- Ability to operate independently as well as work in a team.
- Good fit with our company culture: collaborative, open, humble, driven, analytical, structured,
professional, fun, passionate, entrepreneurial with a hands-on - “Can do” mindset
Good to have
- Basic understanding of data modeling is preferred.
- Some experience with languages for ETL such as SQL, Python is a plus.
- Some experience with data visualization tools such as Data Studio, Power BI, Tableau, etc. is a
plus.
What we offer
- Competitive compensation (with 13th month annual bonus)
Opportunity to be a key part of a fast-growing leading Ecommerce enabler in SEA, offering
exciting career opportunities
- Ample opportunity for personal and professional development, both on the job and through
regular training (Ecommerce & (Digital) Marketing topics, soft skills and leadership training).
- English speaking international environment, open, collaborative and fun culture, and a nice & centrally located office (WeWork D4)
- Additional 2 annual leave (besides regular annual leave for all Vietnamese holidays recognized by Vietnamese labor law and 12 days personal annual leave).
About Intrepid Vietnam
Intrepid is a fast-growing and industry-leading ecommerce enabler, making sellers and brands successful in Ecommerce on all marketplace platforms across South East Asia through a combination of software solutions and value-added services across store management, online marketing, customer service (e.g. chat), data & intelligence, and fulfilment & logistics. The company operates in Indonesia, Philippines,Singapore, Vietnam, Thailand and soon Malaysia, was built by ex-Lazada founders and is run by a young, enthusiastic and energetic team, looking to help brands and sellers seize the full potential of the ecommerce opportunity in South East Asia
Application:
Email title [Job name] [YourName] [+ Badinulomember-để được ưu tiên xíu xíu <3 ]
contact:
[email protected]
run python 在 prasertcbs Youtube 的評價
Anaconda Python เป็น Python ที่ได้รับความนิยมเป็นอย่างมากในหมู่นักพัฒนาโปรแกรม รวมถึงผู้สนใจด้านวิทยาศาสตร์ข้อมูล (Data Science) เพราะติดตั้งได้ง่าย รวมถึงการติดตั้ง package ต่าง ๆ ที่สำคัญ โดยเฉพาะ IPython/Jupyter Notebook, Numpy, Scipy, Pandas, Matplotlib, scikit-learn และอื่น ๆ อีกมากมาย
นอกจากนี้ Anaconda ยังมีโปรแกรมที่ช่วยบริหารจัดการ package ที่ชื่อว่า conda ซึ่งทำให้สามารถติดตั้ง update รวมถึงสร้าง environment ได้อย่างง่ายดายและมีประสิทธิภาพ ซึ่งช่วยให้สามารถเลือกที่จะ run Python 2 และ 3 ได้โดยง่าย
เชิญสมัครเป็นสมาชิกของช่องนี้ได้ที่ ► https://www.youtube.com/subscription_center?add_user=prasertcbs
playlist สอนภาษา Python ► https://www.youtube.com/playlist?list=PLoTScYm9O0GH4YQs9t4tf2RIYolHt_YwW
playlist สอนภาษาไพธอน Python OOP ► https://www.youtube.com/playlist?list=PLoTScYm9O0GEIZzlTKPUiOqkewkWmwadW
playlist สอน Python 3 GUI ► https://www.youtube.com/playlist?list=PLoTScYm9O0GFB1Y3cCmb9aPD5xRB1T11y
playlist สอนภาษา C เบื้องต้น ► https://www.youtube.com/playlist?list=PLoTScYm9O0GHHgz0S1tSyIl7vkG0y105z
playlist สอนภาษา C++ ► https://www.youtube.com/playlist?list=PLoTScYm9O0GEfZwqM2KyCBcPTVsc6cU_i
playlist สอนภาษา C# ► https://www.youtube.com/playlist?list=PLoTScYm9O0GE4trr-XPozJRwaY7V9hx8K
playlist สอนภาษา Java ► https://www.youtube.com/playlist?list=PLoTScYm9O0GF26yW0zVc2rzjkygafsILN
playlist สอนภาษา PHP เบื้องต้น ► https://www.youtube.com/playlist?list=PLoTScYm9O0GH_6LARFxozL_viEsXV2wgO
playlist สอนภาษา R เบื้องต้น ► https://www.youtube.com/playlist?list=PLoTScYm9O0GF6qjrRuZFSHdnBXD2KVICp

run python 在 prasertcbs Youtube 的評價
Visual Studio Code เป็นหนึ่งใน text editor ที่ได้รับความนิยมสูงมากในหมู่นักพัฒนาโปรแกรม
เนื้อหาในคลิปจะสอนถึงวิธีการติดตั้ง Python Extension บน Visual Studio Code เพื่อให้สามารถพัฒนาโปรแกรม Python ได้ง่ายขึ้น เช่น การทำ IntelliSense, Debugger, การกำหนด python environment ที่ต้องการใช้ในการพัฒนาโปรแกรม รวมถึงการ run โปรแกรมให้สะดวกยิ่งขึ้น
เชิญสมัครเป็นสมาชิกของช่องนี้ได้ที่ ► https://www.youtube.com/subscription_center?add_user=prasertcbs
สอนการใช้งาน Visual Studio Code เบื้องต้น ► https://www.youtube.com/playlist?list=PLoTScYm9O0GEo8pnhJb-m-MGVGDvGb4bB
สอนภาษา Python ► https://www.youtube.com/playlist?list=PLoTScYm9O0GH4YQs9t4tf2RIYolHt_YwW
สอนภาษาไพธอน Python OOP ► https://www.youtube.com/playlist?list=PLoTScYm9O0GEIZzlTKPUiOqkewkWmwadW
สอน Python 3 GUI ► https://www.youtube.com/playlist?list=PLoTScYm9O0GFB1Y3cCmb9aPD5xRB1T11y
สอน git เบื้องต้น ► https://www.youtube.com/playlist?list=PLoTScYm9O0GGsV1ZAyP4m_iyAbflQrKrX
#prasertcbs #prasertcbs_visual_studio_code

run python 在 prasertcbs Youtube 的評價
Visual Studio Code เป็นหนึ่งใน text editor ที่ได้รับความนิยมสูงมากในหมู่นักพัฒนาโปรแกรม
เนื้อหาในคลิปจะสอนถึงวิธีการติดตั้ง
► Java SDK 10 (http://www.oracle.com/technetwork/java/javase/downloads/jdk10-downloads-4416644.html)
► Visual Studio Code (https://code.visualstudio.com/download)
► Java Extension Pack บน Visual Studio Code เพื่อให้สามารถพัฒนาโปรแกรม Java ได้ง่ายขึ้น
► Code runner extension เพื่อให้ compile และ run โปรแกรมให้สะดวกยิ่งขึ้น
เชิญสมัครเป็นสมาชิกของช่องนี้ได้ที่ ► https://www.youtube.com/subscription_center?add_user=prasertcbs
playlist สอนการใช้งาน Visual Studio Code เบื้องต้น ► https://www.youtube.com/playlist?list=PLoTScYm9O0GEo8pnhJb-m-MGVGDvGb4bB
playlist สอนภาษา Java ►https://www.youtube.com/playlist?list=PLoTScYm9O0GF26yW0zVc2rzjkygafsILN
playlist สอนภาษา Python ► https://www.youtube.com/playlist?list=PLoTScYm9O0GH4YQs9t4tf2RIYolHt_YwW
playlist สอนภาษาไพธอน Python OOP ► https://www.youtube.com/playlist?list=PLoTScYm9O0GEIZzlTKPUiOqkewkWmwadW
playlist สอน Python 3 GUI ► https://www.youtube.com/playlist?list=PLoTScYm9O0GFB1Y3cCmb9aPD5xRB1T11y
playlist สอน git เบื้องต้น ► https://www.youtube.com/playlist?list=PLoTScYm9O0GGsV1ZAyP4m_iyAbflQrKrX
#prasertcbs #prasertcbs_visual_studio_code #prasertcbs_Java

run python 在 How to Run Your Python Scripts - Real Python 的相關結果
A widely used way to run Python code is through an interactive session. To start a Python interactive session, just open a command-line or terminal and then ... ... <看更多>
run python 在 Python on Windows FAQ — Python 3.10.0 documentation 的相關結果
How do I run a Python program under Windows?¶ · py command is recognized, you can give your Python script to it. You'll have to give either an absolute or a ... ... <看更多>
run python 在 第2 章執行Python 程式 的相關結果
與「Add Python 3.x to PATH」並點擊「Install Now」開始安裝 ... (Top tab) Run (執行頁籤) → "Run file as script" (以腳本模式執行檔案) → (點選) "Shortcut 1" ... ... <看更多>