I have I double value like this one 17.125. It should be rounded up to 17.13

If I use the simple method like %.2f it shows me 17.12 I also followed several methods described in other threads here like using NumberFormatter and so on - but without luck.

Maybe someone has an advice for me to fix this problem? Do I have to round it on my own?

Try This:

float number=17.125;
NSNumberFormatter *format = [[NSNumberFormatter alloc]init];
[format setNumberStyle:NSNumberFormatterDecimalStyle];
[format setRoundingMode:NSNumberFormatterRoundHalfUp];
[format setMaximumFractionDigits:];
NSString *temp = [format stringFromNumber:[NSNumber numberWithFloat:number]];
NSLog(@"%@",temp);

http://stackoverflow.com/questions/15109963/ios-round-double-value-to-2-decimal-digits-and-round-3rd-decimal-digit-up

 

iOS Round Double value to 2 decimal digits and round 3rd decimal digit up的更多相关文章

  1. retain two decimal digits.

    package kju.o; import static kju.print.Printer.*; import java.text.*; class MathDemo { public static ...

  2. java中常用到的math方法(Math.PI、Math.random()、Math.abs(double)、Math.floor(double)、Math.ceil(double)、Math.round(double))

    public class MathDemo { public static void main(String args[]){ /** * abs求绝对值 */ System.out.println( ...

  3. java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result异常的解决方法

    今天在写一个JAVA程序的时候出现了异常:java.lang.ArithmeticException: Non-terminating decimal expansion; no exact repr ...

  4. BigDecimal除法运算出现java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result的解决办法

    BigDecimal除法运算出现java.lang.ArithmeticException: Non-terminating decimal expansion; no exact represent ...

  5. Bigdecimal: Non-terminating decimal expansion; no exact representable decimal result.

    做除法没有指定保留小数点后几位,就会抛出此异常. 因为会除不尽 Non-terminating decimal expansion; no exact representable decimal re ...

  6. 除法运算时的一个常见异常之java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.

    一.背景 今天在计算库存消耗百分比(消耗的库存/总库存)的时候遇到了一个错误,java.lang.ArithmeticException: Non-terminating decimal expans ...

  7. Non-terminating decimal expansion; no exact representable decimal result.

    Non-terminating decimal expansion; no exact representable decimal result.  翻译为:非终止十进制扩展; 没有确切的可表示的小数 ...

  8. iOS项目double、float精度丢失解决办法

    描述 在iOS项目中老是遇到double.float精度丢失的问题 PS: NSString * jsonStr = @"{\"9.70\":9.70,\"67 ...

  9. 【java】java.lang.Math:public static long round(double a)和public static int round(float a)

    package math; public class TestMath_round { public static void main(String[] args) { System.out.prin ...

随机推荐

  1. C#的math类的全部运算方法

    Abs 返回指定数字的绝对值.Acos 返回余弦值为指定数字的角度.Asin 返回正弦值为指定数字的角度.Atan 返回正切值为指定数字的角度.Atan2 返回正切值为两个指定数字的商的角度.BigM ...

  2. Keil_uvision 基本使用教程

    Keil C51 V9.00 即09年发布的最新版本uVision 4,版本外观改变比较大,可以使用以前的注册文件.如果全新安装,在VISTA或者WIN 7系统下,请使用管理员方式运行,然后注册即可无 ...

  3. java实现下载excel功能

    1,获取服务器现有excel文件 public List<Object[]> getObject(String filePath){ log.info("**文件路径为:**&q ...

  4. 【python】Python 中的 classmethod 和 staticmethod

    Python 中的 classmethod 和 staticmethod 有什么具体用途? 推荐地址:http://www.cnblogs.com/wangyongsong/p/6750454.htm ...

  5. 23种设计模式(1)-Facade设计模式

    前记 曾经我遇见的一个需求是这样的,接口A有个方法void methodA(),类B需要实现接口A的methodA()方法,并且在类B中需要把methodA()方法内部处理逻辑获得的结果利用C类实例的 ...

  6. Northwind测试学习用数据库

    下载地址: https://northwinddatabase.codeplex.com/

  7. Hdu2068 RPG的错排 2017-06-27 15:27 30人阅读 评论(0) 收藏

    RPG的错排 Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submis ...

  8. 当Windows Phone遇到Windows 8

    三年前,Windows Phone系统的发布表示了微软夺回移动市场的决心.一年前,Windows 8的发布,昭示着Windows Phone系统取得的成功——扁平化图标风格.动态磁贴.SkyDrive ...

  9. std::set 中内部元素有序条件删除的理解

    std::set 中内部元素有序条件删除的理解 1. std::set中的元素是有序排列的 注意:Set集合中的元素通过iterator的引用,但是不能修改. 元素排序: (1)元素中实现比较oper ...

  10. hdu 5050 大数

    http://acm.hdu.edu.cn/showproblem.php?pid=5050 大数模板最大公约数 信kuangbin,能AC #include <cstdio> #incl ...