Jas*_*ain 10 double string-interpolation swiftui
我有一个美元(货币)金额,我试图在 Text 元素中使用字符串插值来显示该金额。目前,它显示如 9.9900000。我希望该值仅显示为 9.99。
struct ContentView: View {
var productPrice: Double = 9.99
var body: some View {
Text("\(productPrice)")
}
}
Run Code Online (Sandbox Code Playgroud)
q8y*_*yas 31
struct ContentView: View {
var productPrice: Double = 9.99
var body: some View {
Text("\(productPrice, specifier: "%.2f")")
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4931 次 |
| 最近记录: |