Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
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
690
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
50
SwiftUIで使いやすいToastの作り方 / How to build a Toast system which is easy to use in SwiftUI
lovee
3
680
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
26
8.3k
属人化しない為の勉強会作り / To make tech meetups with less personal dependencies
lovee
0
280
偏見と妄想で語るスクリプト言語としての Swift / Swift as a Scripting Language
lovee
2
790
danger-swift-kantoku
lovee
1
490
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
Leveling Up Developer Tooling for the Modern Rails & Hotwire Era @ Ruby Türkiye, November 2024
marcoroth
0
150
The rollercoaster of releasing an Android, iOS, and macOS app with Kotlin Multiplatform | droidcon Italy
prof18
0
110
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
140
[KR] Open-Source Ecosystems
skydoves
0
110
最新TCAキャッチアップ
0si43
0
250
[FlutterKaigi2024] Effective Form 〜Flutterによる複雑なフォーム開発の実践〜
chocoyama
0
3.9k
Serverless苦闘史
mosh_inc
0
130
As an Engineers, let's build the CRM system via LINE Official Account 2.0
clonn
1
570
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.3k
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
3
1.4k
Leverage LLMs in Java with LangChain4j and Quarkus
hollycummins
0
110
Modular Monolith Monorepo ~シンプルさを保ちながらmonorepoのメリットを最大化する~
yuisakamoto
10
3.6k
Featured
See All Featured
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
Building Your Own Lightsaber
phodgson
103
6.1k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
Designing the Hi-DPI Web
ddemaree
280
34k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.2k
Agile that works and the tools we love
rasmusluckow
327
21k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
How STYLIGHT went responsive
nonsquared
95
5.2k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
17k
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