您好,欢迎来到二三四教育网。
搜索
您的当前位置:首页仅支持X位整数Y位小数 的处理

仅支持X位整数Y位小数 的处理

来源:二三四教育网

仅支持X位整数Y位小数 的处理:

-(void) handleInPut:(UITextField*)textfield  IntBitCount:(NSInteger) intBitCount dotBitCount:(NSInteger)dotBitCount toastMsg:(NSString*) msg{

    BOOLisHaveDot =YES;

    if([textfield.textrangeOfString:@"."].location==NSNotFound) {

        isHaveDot =NO;

    }

    if(isHaveDot) {//存在小数点

        NSRangerange = [textfield.textrangeOfString:@"."];

        if(textfield.text.length- range.location> (dotBitCount +1)) {

            [WAGToastUtil showToastInRootViewWithMsg:msg];

            NSUIntegerlen = textfield.text.length;

            textfield.text= [textfield.textsubstringToIndex:len -1];

        }

        if(range.location> intBitCount) {

            [WAGToastUtil showToastInRootViewWithMsg:msg];

            textfield.text= [textfield.textsubstringFromIndex:range.location- intBitCount];

        }

    }else{

        NSUIntegerlen = textfield.text.length;

        if(len > intBitCount) {

            [WAGToastUtil showToastInRootViewWithMsg:msg];

            textfield.text= [textfield.textsubstringToIndex:intBitCount];

        }

    }

}

调用:

        [self handleInPut:textfield IntBitCount:6 dotBitCount:2 toastMsg:@"仅支持6位整数2位小数"];

判断是空字符串

- (BOOL)isBlankString:(NSString*)str {

    NSString *noBlankStr = [str stringByReplacingOccurrencesOfString:@" " withString:@""];

    noBlankStr = [noBlankStrstringByReplacingOccurrencesOfString:@"\n" withString:@""];

    noBlankStr = [noBlankStrstringByReplacingOccurrencesOfString:@"\r" withString:@""];

    return(noBlankStr.length==0);

}

本文如未解决您的问题请添加抖音号:51dongshi(抖音搜索懂视),直接咨询即可。

热门图文

Copyright © 2019-2025 how234.cn 版权所有 赣ICP备2023008801号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务