Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
JavaScriptは小数が苦手
Search
Toru
February 22, 2022
Programming
49
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
JavaScriptは小数が苦手
2022/2/22 はじめてのIT勉強会(仙台)
Toru
February 22, 2022
Transcript
16 slides
JavaScriptখ͕ۤख ʙුಈখܭࢉਖ਼֬ʹͰ͖ͳ͍ʙ 2022/2/22ɹגࣜձࣾBTMɹੴࠇ
0.3 - 0.1 = ?
console.log( 0.3 - 0.1 ) > 0.19999999999999998
·͔͡ɺJavaScript... σΩΔࢠͩͱࢥ͍ͬͯͨͷʹ...
JavaScriptͰখΛͬͨܭࢉཁҙ • ޡࠩͷݪҼɹ ɹ 10ਐͷখ 2ਐʹ͏·͘ม͕Ͱ͖ͳ͍ͱ͖͕͋Δ͔Β ɹ(͖ͬ͞ͷྫ)ɹ0.2 Λ2ਐมɹɹ0.00110011.....ʢ॥খʣ • JavaScriptͷNumberܕ
ɹුಈখʢIEEE754ʣΛ࠾༻
࣮ࡍʹ͋ͬͨࠔͬͨ ͱ͋Δ͓٬༷ͷCRMʢސ٬ཧγεςϜʣͰ ߹ܭֹۚʢ੫ࠐʣͷֹ͕ۚ߹Θͳ͍
ͲΜͳܭࢉʁ ߹ܭֹۚʢ੫ࠐʣ͕߹Θͳ͍ ߹ܭֹۚ(੫ൈ) ফඅ੫ֹ(10%) ߹ܭֹۚ(੫ࠐ) : 3,000,000ԁ : 300,000ԁ :
3,300,000ԁ Α͋͘Δ՝੫ܭࢉͰ͢
ͲΜͳ෩ʹ߹Θͳ͔ͬͨͷʁ ߹ܭֹۚʢ੫ࠐʣ͕߹Θͳ͍ Math.ceil(3000000 * 1.1) > 3300001 ߹ܭֹۚ(੫ൈ) ফඅ੫ֹ(10%) ߹ܭֹۚ(੫ࠐ)
: 3,000,000ԁ : 300,000ԁ : 3,300,000ԁ
ͲΜͳ෩ʹ߹Θͳ͔ͬͨͷʁ ߹ܭֹۚʢ੫ࠐʣ͕߹Θͳ͍ Math.ceil(3000000 * 1.1) > 3300001 ߹ܭֹۚ(੫ൈ) ফඅ੫ֹ(10%) ߹ܭֹۚ(੫ࠐ)
: 3,000,000ԁ : 300,000ԁ : 3,300,000ԁ ̍ԁͣΕͨɾɾɾ 3,300,001ԁ
ͳͥ߹Θͳ͔ͬͨͷʁ ߹ܭֹۚʢ੫ࠐʣ͕߹Θͳ͍ Math.ceil (3000000 * 1.1) > 3300001 // NG
A . গͷޡࠩʴؙΊॲཧͷ͍ͤͰ͢ খΛΓ্͛ͯʹ͢Δ 3300000.0000000005
Ͳ͏͢Εྑ͔ͬͨʁ ߹ܭֹۚʢ੫ࠐʣ͕߹Θͳ͍ Math.ceil (3000000 * 110 / 100) > 3300000
// OK A . ʢҊͦͷ̍ʣܭࢉʹখΛΘͳ͍ 3300000
Ͳ͏͢Εྑ͔ͬͨʁ ߹ܭֹۚʢ੫ࠐʣ͕߹Θͳ͍ Math.ceil(BigNumber(3000000).times(1.1)) > 3300000 // OK A . ʢҊͦͷ̎ʣখܭࢉ༻ϥΠϒϥϦΛ༻͢Δ
3300000 bignumber.jsΛͬͨྫ
ුಈখ(floatdouble)Ͱͳ͍ܕΫϥεΛ͓͏ ଞͷݴޠʁ Java Ruby MySQL BigDecimal BigDecimal DECIMAL, NUMERIC
খΛؚΉܭࢉਖ਼֬ͳ݁Ռ͕ग़ͳ͍͜ͱ͕͋Δ ·ͱΊ ͳΔ͘ʹஔ͖͑ͯܭࢉ͢Δ ුಈখͰͳ͘ݻఆখͷܕΫϥεΛ͏ ͍͟ͱͳͬͨΒখܭࢉ༻ͷϥΠϒϥϦͳͲ༻Λݕ౼ 0.3 - 0.1 number, float,
double ( 3 - 1 ) / 10 decimalܥ JavaScriptͳΒbignumber.jsdecimal.js
͜ΕͰ͏ɺখܭࢉා͘ͳ͍Ͱ͢Ͷʂ ऴΘΔલʹͪΐͬͱ͚ͩએ...
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠
More Decks by Toru
See All by Toru
リーダブルコード~誤解されない名前~
toru_i
0
4
面白楽しいIT用語
toru_i
0
52
Other Decks in Programming
See All in Programming
Canvas 2D Context Next
petamoriken
0
690
社内AIエージェント「Askワンバン」における コストチューニングの取り組み
t0yohei
0
180
AIが生成したコードは読むべきか?抽象化設計とコードの品質保証 / abstraction-design-and-quality
minodriven
17
9.6k
AppFunctionsの内部実装を紐解く
hiroaki404
1
130
Datadog を OTel にするメリットを考察する — Datadog との併用を実アプリで確かめる / Examining the Benefits of Moving Datadog to OTel — Testing OTel Alongside Datadog in a Real App
seike460
PRO
1
100
joyful-journey-spring-boot.pdf
hollycummins
0
130
Claude Codeのおかげでやりたいことがやれるようになったんだよォー!
sms_tech
0
190
あなたはMCPの機能を、まだ知らない。
4geru
1
740
特急いなほ as a Workflow / 20261107jaws-festa-2026-akita-lt
kasacchiful
PRO
0
110
protojson における文字化けの扱い
kazuki1023
0
470
Rails初心者がパスキーを実装してみて大変だったこと
ktombow
0
240
はじめてのKubernetesコントリビューション
nasa9084
0
330
Featured
See All Featured
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
490
Amusing Abliteration
ianozsvald
1
400
Faster Mobile Websites
deanohume
310
32k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.9k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
590
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
4
1.3k
Mind Mapping
helmedeiros
1
460
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
350
Designing Experiences People Love
moore
143
24k
エンジニアに許された特別な時間の終わり
watany
109
250k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
310
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
890