bearkuan
bearkuan
2016-01-06 12:14

swift 不正确浮点数相减结果 IOS

  • swift

贴上代码:
//
// main.swift
// HelloSwift
//
// Created by BearKuan on 15/11/22.
// Copyright © 2015年 BearKuan. ****All rights reserved.
//

import Foundation

print("Hello, World!")

var m = 100.0
var i = 0.1

while(i<99.9){

i = i + 0.2
m = m + 0.1;
print (m)

}

m = m - 99.9
print("m=",m)

贴上结果
。。。。。。
149.399999999997
149.499999999997
149.599999999997
149.699999999997
149.799999999997
149.899999999997
m= 49.9999999999972
Program ended with exit code: 0

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐

换一换