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
710
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
66
SwiftUIで使いやすいToastの作り方 / How to build a Toast system which is easy to use in SwiftUI
lovee
3
750
SwiftUIで二重スクロール作ってみた / When I tried to make a dual-scroll-ish view in SwiftUI
lovee
1
260
Observation のあれこれ / A brief introduction about Observation
lovee
3
350
ChatGPT 時代の勉強 / Learning under ChatGPT era
lovee
27
8.6k
属人化しない為の勉強会作り / To make tech meetups with less personal dependencies
lovee
0
290
偏見と妄想で語るスクリプト言語としての Swift / Swift as a Scripting Language
lovee
2
820
danger-swift-kantoku
lovee
1
510
A story about me trying to make a router that manages when, how and which view to transit in a SwiftUI app
lovee
1
410
Other Decks in Programming
See All in Programming
Simple組み合わせ村から大都会Railsにやってきた俺は / Coming to Rails from the Simple
moznion
3
2.1k
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
930
EC2からECSへ 念願のコンテナ移行と巨大レガシーPHPアプリケーションの再構築
sumiyae
3
590
ドメインイベント増えすぎ問題
h0r15h0
2
560
責務を分離するための例外設計 - PHPカンファレンス 2024
kajitack
9
2.4k
Внедряем бюджетирование, или Как сделать хорошо?
lamodatech
0
940
ESLintプラグインを使用してCDKのセオリーを適用する
yamanashi_ren01
2
240
Запуск 1С:УХ в крупном энтерпрайзе: мечта и реальность ПМа
lamodatech
0
950
毎日13時間もかかるバッチ処理をたった3日で60%短縮するためにやったこと
sho_ssk_
1
550
PHPUnitしか使ってこなかった 一般PHPerがPestに乗り換えた実録
mashirou1234
0
420
DevinとCursorから学ぶAIエージェントメモリーの設計とMoatの考え方
itarutomy
0
140
Swiftコンパイラ超入門+async関数の仕組み
shiz
0
170
Featured
See All Featured
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
870
Making Projects Easy
brettharned
116
6k
RailsConf 2023
tenderlove
29
970
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.6k
For a Future-Friendly Web
brad_frost
176
9.5k
Facilitating Awesome Meetings
lara
51
6.2k
A better future with KSS
kneath
238
17k
It's Worth the Effort
3n
183
28k
Product Roadmaps are Hard
iamctodd
PRO
50
11k
4 Signs Your Business is Dying
shpigford
182
22k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
960
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