iOS Round Double value to 2 decimal digits and round 3rd decimal digit up
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的更多相关文章
- retain two decimal digits.
package kju.o; import static kju.print.Printer.*; import java.text.*; class MathDemo { public static ...
- 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( ...
- java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result异常的解决方法
今天在写一个JAVA程序的时候出现了异常:java.lang.ArithmeticException: Non-terminating decimal expansion; no exact repr ...
- BigDecimal除法运算出现java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result的解决办法
BigDecimal除法运算出现java.lang.ArithmeticException: Non-terminating decimal expansion; no exact represent ...
- Bigdecimal: Non-terminating decimal expansion; no exact representable decimal result.
做除法没有指定保留小数点后几位,就会抛出此异常. 因为会除不尽 Non-terminating decimal expansion; no exact representable decimal re ...
- 除法运算时的一个常见异常之java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.
一.背景 今天在计算库存消耗百分比(消耗的库存/总库存)的时候遇到了一个错误,java.lang.ArithmeticException: Non-terminating decimal expans ...
- Non-terminating decimal expansion; no exact representable decimal result.
Non-terminating decimal expansion; no exact representable decimal result. 翻译为:非终止十进制扩展; 没有确切的可表示的小数 ...
- iOS项目double、float精度丢失解决办法
描述 在iOS项目中老是遇到double.float精度丢失的问题 PS: NSString * jsonStr = @"{\"9.70\":9.70,\"67 ...
- 【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 ...
随机推荐
- create table b1 as select * from b建表锁表测试
A: create table a1 like a; insert into a1 as select * from a; B: create table b1 as select * from b; ...
- js动态删除某一行,内容超出单元格后超出的部分用省略号代替
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <s ...
- WordPaster-dedecms5.7整合教程
1.1. 与dedecms5.7整合 本教程中提到的插件文件可在官网的php-ckeditor3x示例中找到. 示例:http://www.ncmem.com/download/WordPaster2 ...
- MIT Molecular Biology 笔记2 DNA的突变和修复
视频 https://www.bilibili.com/video/av7973580?from=search&seid=16993146754254492690 教材 Molecular ...
- noip第27课作业
1. 繁忙的都市 [问题描述] 城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造.城市C的道路是这样分布的:城市中有n个交叉路口,有些交叉路口之间有道路相连,两个 ...
- How to give a math lecture
摘自 http://www.timhsu.net/courses/generic/proof.pdf 或 http://www.timhsu.net/courses/generic/how-to- ...
- 广搜 poj3278 poj1426 poj3126
Catch That Cow Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u Ja ...
- uniGUI for C++ builder下如何利用FastReport实现数据记录本地打印
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/dlboy2018/article/details/81040260 (中行雷威2018.7.14于杭 ...
- Jquery学习(表单-Button)-----jQuery1.4.2
<html> <head> <base href="<%=basePath%>"> <title>My JSP 'jqu ...
- 企业项目开发--cookie(1)
此文已由作者赵计刚授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 注:本章代码基于<第五章 企业项目开发--mybatis注解与xml并用>的代码,链接如下: h ...