删除超过2个尾随零 [英] Remove More Than 2 Trailing zero

查看:147
本文介绍了删除超过2个尾随零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在堆栈溢出中读到了很多问题,我想要的是删除小数后面的2个或两个以上的尾随零。即:

I have read many question in stack overflow, what I want is remove 2 or more than two trailing zero behind the decimal. i.e:

12.00 ==> 12
12.30 ==> 12.30
12.35 ==> 12.35
12.345678 ==> 12.34


推荐答案

NSNumberFormatter *twoDecimalPlacesFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[twoDecimalPlacesFormatter setMaximumFractionDigits:2];
[twoDecimalPlacesFormatter setMinimumFractionDigits:0];

return [twoDecimalPlacesFormatter stringFromNumber:number];

这篇关于删除超过2个尾随零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆