zoukankan      html  css  js  c++  java
  • iOS 去掉小数点后边多余的0

    -(NSString*)removeFloatAllZero:(NSString*)string
    {
        
        NSString * testNumber = string;
        NSString * outNumber = [NSString stringWithFormat:@"%@",@(testNumber.floatValue)];
        
    //    价格格式化显示
        NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
        formatter.numberStyle = kCFNumberFormatterDecimalStyle;
        NSString *formatterString = [formatter stringFromNumber:[NSNumber numberWithFloat:[outNumber doubleValue]]];
        
        NSRange range = [formatterString rangeOfString:@"."]; //现获取要截取的字符串位置
        NSLog(@"--------%lu",(unsigned long)range.length);
     
        if (range.length>0) {
            
            NSString * result = [formatterString substringFromIndex:range.location]; //截取字符串
            
            if (result.length>=4) {
                
                formatterString=[formatterString substringToIndex:formatterString.length-1];
            }
            
        }
    
        NSLog(@"Formatted number string:%@",formatterString);
        
        NSLog(@"Formatted number string:%@",outNumber);
        //    输出结果为:[1223:403] Formatted number string:123,456,789
        
        return formatterString;
    }
  • 相关阅读:
    Pytorch笔记 (2) 初识Pytorch
    Pytorch笔记 (1) 初始神经网络
    c++ 数据抽象 、封装 接口(抽象类)
    c++ 多态
    c++ 重载运算符和重载函数
    c++ 继承
    c++面向对象 —— 类和对象
    c++ 结构
    c++ 基本的输入输出
    c++ 引用 日期&时间
  • 原文地址:https://www.cnblogs.com/xujiahui/p/6668375.html
Copyright © 2011-2022 走看看