Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Decimal、正しく使ってる? / Are you using Decimal correc...
Search
Elvis Shi
December 15, 2021
Programming
4
700
Decimal、正しく使ってる? / Are you using Decimal correctly?
Elvis Shi
December 15, 2021
Tweet
Share
More Decks by Elvis Shi
See All by Elvis Shi
How did I build an Open-Source SwiftUI Toast Library
lovee
1
57
SwiftUIで使いやすいToastの作り方 / How to build a Toast system which is easy to use in SwiftUI
lovee
3
710
SwiftUIで二重スクロール作ってみた / When I tried to make a dual-scroll-ish view in SwiftUI
lovee
1
250
Observation のあれこれ / A brief introduction about Observation
lovee
3
340
ChatGPT 時代の勉強 / Learning under ChatGPT era
lovee
27
8.5k
属人化しない為の勉強会作り / To make tech meetups with less personal dependencies
lovee
0
280
偏見と妄想で語るスクリプト言語としての Swift / Swift as a Scripting Language
lovee
2
800
danger-swift-kantoku
lovee
1
500
A story about me trying to make a router that manages when, how and which view to transit in a SwiftUI app
lovee
1
400
Other Decks in Programming
See All in Programming
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
190
テスト自動化失敗から再挑戦しチームにオーナーシップを委譲した話/STAC2024 macho
ma_cho29
1
1.3k
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
120
RWC 2024 DICOM & ISO/IEC 2022
m_seki
0
210
menu基盤チームによるGoogle Cloudの活用事例~Application Integration, Cloud Tasks編~
yoshifumi_ishikura
0
110
PSR-15 はあなたのための ものではない? - phpcon2024
myamagishi
0
120
nekko cloudにおけるProxmox VE利用事例
irumaru
3
430
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
770
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
350
良いユニットテストを書こう
mototakatsu
8
2.3k
PHPで学ぶプログラミングの教訓 / Lessons in Programming Learned through PHP
nrslib
2
260
Featured
See All Featured
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.2k
Bash Introduction
62gerente
608
210k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Scaling GitHub
holman
458
140k
RailsConf 2023
tenderlove
29
940
Adopting Sorbet at Scale
ufuk
73
9.1k
The Language of Interfaces
destraynor
154
24k
Git: the NoSQL Database
bkeepers
PRO
427
64k
For a Future-Friendly Web
brad_frost
175
9.4k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Transcript
%FDJNBMɺਖ਼ͬͯ͘͠Δʁ forJ1IPOF%FW4BQQPSPGFBU)","5"TXJGU
} var employedBy = "YUMEMI Inc." var job = "iOS
Tech Lead" var favoriteLanguage = "Swift" var twitter = "@lovee" var qiita = "lovee" var github = "el-hoshino" var additionalInfo = """ M1 Max MacBook Proࠓಧ͍ͨʂ """ final class Me: Developable, Talkable {
ʲใʳΏΊΈɺ҉߸௨՟Λൃߦʂ ˞ӕͰ͢ɻ
ͱ͍͏Θ͚Ͱ ΏΊΈͷڅ༩:VNF$PJOͰࢧڅʹ ˞ӕͰ͢ɻ
// ࠓ݄ͷڅ༩ var myYumeCoin = 0.2 // ࠓ݄ͷϘʔφε myYumeCoin +=
0.1 // ϘʔφεΛͬͯങ͍ʂ myYumeCoin -= 0.1 // ߴ֬ೝ print(myYumeCoin) // 0.20000000000000004 ??????
ͳͥ͜Μͳ͜ͱ͕ى͜Δͷ͔ w 4XJGUͰখΛѻ͏ͱ͖ɺσϑΥϧτͰDouble͕ ΘΕΔ w Doubleʮഒਫ਼ුಈখʯͳͷͰɺਫ਼ͷ Ͱͦͦਖ਼֬ʹදͤͳ͍ࣈ͕ͨ͘͞Μ͋Δ w େͷ߹ͦͷؙΊΒΕͨࣈͰʹͳΒͳ͍ ͕ɺۚ༥ܥͳͲͷ߹ਖ਼֬ʹѻ͏ඞཁ͕͋Δ
Decimal
Decimalܕ w ුಈখΛेਐϕʔεͰѻ͏ͨΊͷܕ w ༗ޮܻ͕ܻ w ༗ޮܻൣғͰ͋Εेਐදهͷޡ͕ࠩͳ͍
// ࠓ݄ͷڅ༩ var myYumeCoin = 0.2 // ࠓ݄ͷϘʔφε myYumeCoin +=
0.1 // ϘʔφεΛͬͯങ͍ʂ myYumeCoin -= 0.1 // ߴ֬ೝ print(myYumeCoin) // 0.20000000000000004 ??????
import Foundation // ࠓ݄ͷڅ༩ var myYumeCoin: Decimal = 0.2 //
ࠓ݄ͷϘʔφε myYumeCoin += 0.1 // ϘʔφεΛͬͯങ͍ʂ myYumeCoin -= 0.1 // ߴ֬ೝ print(myYumeCoin) // 0.2 🎉 'PVOEBUJPO͕ඞཁ ܕΛ໌ࣔతʹ%FDJNBMʹࢦఆ
DecimalɺŜƃŤƄƃŬžŜŘŢŦ
DecimalɺŜƃŤƄƃŬžŜŘŢŦ ͱɺࢥͬͨʁ
import Foundation // ࠓ݄ͷڅ༩ var myYumeCoin: Decimal = 0.2 //
ࠓ݄ͷϘʔφε myYumeCoin += 0.1 // ϘʔφεΛͬͯങ͍ʂ myYumeCoin -= 0.1 // ߴ֬ೝ print(myYumeCoin) // 0.2 🎉
import Foundation // ࠓ݄ͷڅ༩ var myYumeCoin: Decimal = 0.2 //
ࠓ݄ͷϘʔφε myYumeCoin += 0.1 // ϘʔφεΛͬͯങ͍ʂ myYumeCoin -= 0.1 // Decimal Λͬͯਖ਼֬ͳڅ༩ܭࢉ͕Ͱ͖͔ͨΒ͍͑Ϙʔφεʂ myYumeCoin += 123.456 // ߴ֬ೝ print(myYumeCoin) // 123.65599999999997952 !!!?????
DecimalɺūŬŹƂŜŽūŘ
DecimalͷϦςϥϧೖ w খϦςϥϧͰDecimalΛೖͰ͖Δͷɺ ExpressibleByFloatLiteralΛར༻ͨ݁͠Ռ w ࣮init(floatLiteral value: Double) w DecimalΛ࡞ΔલʹͦͦઌʹҰճDoubleΛ
࡞ͬͯͦͷ݁ՌΛೖ͍ͯ͠Δ͚ͩʂ
খϦςϥϧͰ DecimalΛೖ͠ͳ͍Ͱʂ
%FDJNBMΛखܰʢʁʣʹѻ͏ͨΊͷ ΠχγϟϥΠβʔ • init(_ value: String, format: Decimal.FormatStyle, lenient:
Bool = true) throws // iOS 15+ • init?(string: String, locale: Locale? = nil) // iOS 7+ • // etc…
import Foundation // ࠓ݄ͷڅ༩ var myYumeCoin: Decimal = 0.2 //
ࠓ݄ͷϘʔφε myYumeCoin += 0.1 // ϘʔφεΛͬͯങ͍ʂ myYumeCoin -= 0.1 // Decimal Λͬͯਖ਼֬ͳڅ༩ܭࢉ͕Ͱ͖͔ͨΒ͍͑Ϙʔφεʂ myYumeCoin += 123.456 // ߴ֬ೝ print(myYumeCoin) // 123.65599999999997952 !!!?????
import Foundation // … // Decimal Λͬͯਖ਼֬ͳڅ༩ܭࢉ͕Ͱ͖͔ͨΒ͍͑Ϙʔφεʂ //myYumeCoin += 123.456
// ࠓͦ͜ʂ myYumeCoin += try! .init("123.456", format: .number) // ߴ֬ೝ print(myYumeCoin) // 123.656 🎉
DecimalɺͪΐͬͱͰ͖͔ͨͳ
ʲࢀߟʳ
IUUQTGPSVNTTXJGUPSHUIPXUPJOJUJBMJ[FEFDJNBM
IUUQTJEFBMSFBMJUZDPNQSPHSBNJOHTXJGUEFDJNBMTUSJOH
ʲએʳ
IUUQTZVNFNJDPOOQBTTDPNFWFOU
IUUQTXXXZVNFNJDPKQDBUFHPSZSFDSVJU