不使用Swift显示小数

时间:2017-09-20 01:54:59

标签: ios swift decimal rounding

我想在标签中显示滑块的值。标签叫做rate,滑块是滑块,我试过这个:

var qry1 =    from c in entities.Transactions
              join p in entities.Products on c.CorporationId equals p.CorporationId
             where c.Branch == branch
                && c.AccountNumber == accountNumber
                && ((Guid?)c.CorporationId).Value == null // This is the secret sauce
           orderby c.TransactionDate descending
            select new
                   {
                       Date = c.TransactionDate,
                       RefNo = c.ReferenceNumber,
                       DlvryAcct = c.DeliveryAccount,
                       Desc = p.Description,
                       GasQty = c.GasQuantity,
                       Total = c.Amount,
                       Balance = c.Balance
                   };

正如你所看到的,我试图绕过它以便不显示小数,但是它不起作用,我仍然有一个小数。请有人帮帮我

1 个答案:

答案 0 :(得分:1)

Swift的舍入函数返回与放入它们相同的类型。因此,如果你围绕一个Double,你得到的回报仍然是Double。要将舍入数字显示为整数,请先将其转换为Int

Int(slidernote.value.rounded())

或者,您可以使用标准C库中的lround函数,该函数返回Int:

import Foundation

lround(slidernote.value)
相关问题