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. 微信小程序两种滑动方式

    竖向滑动: <scroll-view scroll-y="true" style="height: 200rpx;"> <view style ...

  2. poj 3278 Catch That Cow(bfs+队列)

    Description Farmer John has been informed of the location of a fugitive cow and wants to catch her i ...

  3. 文档/视图(01):第一个Demo

    学习文档视图编程的第一个demo,程序比较简单,主要对文档模板,文档,视图等相互关系的一个了解. 功能:菜单添加一个[操作]项,然后新建四份空白文档,点击[操作]之后,在四份空白文档上面各绘制一个Bu ...

  4. idea常用插件介绍

    常用插件 mybatis mapper 选择plugins,搜索mybatis plugin 激活教程 使用 插件的使用

  5. 协程之gevent

    迭代器:     一个实现了__iter__方法和__next__方法的对象,就是迭代器. 生成器:     生成器是一类特殊的迭代器     简单来说:只要在def中有yield关键字的 就称为 生 ...

  6. android sqlite 数据唯一性

    sqlite在遇到数据重复的时候要做判断在插入是不是有点太麻烦了?一个好的数据库设计就可以搞定了. 当要控制唯一性的数据是主键的时候可以设置 CONSTRAINT [] PRIMARY KEY ([Q ...

  7. POJ3692 Kindergarten

    Kindergarten Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6882   Accepted: 3402 Desc ...

  8. Python 7步机器学习

    http://python.jobbole.com/84108/ 由于我们要使用机器学习和科学计算的 packages ,这里建议安装  Anaconda.Anaconda 是一个可在 Linux , ...

  9. 《mysql必知必会》学习_第六章_20180730_欢

    第六章<过滤数据> P35 1. select prod_name,prod_price from products where prod_price=2.5; 2.select prod ...

  10. hdu 4960 数列合并

    http://acm.hdu.edu.cn/showproblem.php?pid=4960 给定一个长度为n的序列,然后再给出n个数bi,表示合成i个数的代价.每次可以将连续的子序列和成一个数,即为 ...