急求ios人民币大小写转换代码(将阿拉伯数字转换位中文大写,允许有两位小数)。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了急求ios人民币大小写转换代码(将阿拉伯数字转换位中文大写,允许有两位小数)。相关的知识,希望对你有一定的参考价值。
-(NSString *)digitUppercase:(NSString *)moneyNSMutableString *moneyStr=[[NSMutableString alloc] initWithString:[NSString stringWithFormat:@"%.2f",[money doubleValue]]];
NSArray *MyScale=@[@"分", @"角", @"元", @"拾", @"佰", @"仟", @"万", @"拾", @"佰", @"仟", @"亿", @"拾", @"佰", @"仟", @"兆", @"拾", @"佰", @"仟" ];
NSArray *MyBase=@[@"零", @"壹", @"贰", @"叁", @"肆", @"伍", @"陆", @"柒", @"捌", @"玖"];
NSMutableString *M=[[NSMutableString alloc] init];
[moneyStr deleteCharactersInRange:NSMakeRange([moneyStr rangeOfString:@"."].location, 1)];
for(int i=moneyStr.length;i>0;i--)
NSInteger MyData=[[moneyStr substringWithRange:NSMakeRange(moneyStr.length-i, 1)] integerValue];
[M appendString:MyBase[MyData]];
if([[moneyStr substringFromIndex:moneyStr.length-i+1] integerValue]==0&&i!=1&&i!=2)
[M appendString:@"元整"];
break;
[M appendString:MyScale[i-1]];
return M;
这是根据别人的C#代码改的
public string chang(string money)
//将小写金额转换成大写金额
double MyNumber = Convert.ToDouble (money );
String[] MyScale = "分", "角", "元", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "兆", "拾", "佰", "仟" ;
String[] MyBase = "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" ;
String M = "";
bool isPoint = false;
if (money.IndexOf(".") != -1)
money = money.Remove(money.IndexOf("."), 1);
isPoint = true;
for (int i = money.Length; i > 0; i--)
int MyData = Convert.ToInt16(money[money.Length - i].ToString ());
M += MyBase[MyData];
if (isPoint==true)
M += MyScale[i - 1];
else
M += MyScale[i + 1];
return M;
参考技术A https://github.com/Sandwych/rmb_converter
有各种语言的实现,选一个自己熟悉的语言,转成obj C吧 参考技术B 一二三四?追问
壹贰...,亿万仟佰拾
js将人民币小写金额转换为大写
以下为es6写法,可以直接在控制栏粘贴运行
/**
* 将人民币小写金额转换为大写
*
* @class RMB
* 示例
let rmb = new RMB()
console.log(rmb.transform(2114523.234))// 贰佰壹拾壹万肆仟伍佰贰拾叁元贰角叁分
*/
class RMB
constructor()
this.numMap = new Map([[0, '零'], [1, '壹'], [2, '贰'], [3, '叁'], [4, '肆'], [5, '伍'], [6, '陆'], [7, '柒'], [8, '捌'], [9, '玖']])
this.integerMap = new Map([[0, '元'], [1, '拾'], [2, '佰'], [3, '仟'], [4, '万'], [5, '拾'], [6, '佰'], [7, '仟'], [8, '亿']])
this.decimalMap = new Map([[0, '分'], [1, '角']])
this.resultSet = new Set()
/**
* 转换
*
* @param number num 待转换的整数
* @returns
* @memberof RMB
*/
transform(num)
this.resultSet.clear()
num = ('' + num).split('.')
let integer = num[0],
decimal = num[1] ? num[1].substr(0, 2) : []
this.add(integer, this.integerMap).add(decimal, this.decimalMap)
return [...this.resultSet].join('')
/**
* 转换
*
* @param array numType
* @param map mapType
* @returns
* @memberof RMB
*/
add(numType, mapType)
let len = numType.length
for (let i = 0; i < len; i++)
this.resultSet.add(this.numMap.get(+numType[i]) + (+numType[i] ? mapType.get(len - i - 1) : ''))
return this
let rmb = new RMB()
console.log(rmb.transform(2114523.234))// 贰佰壹拾壹万肆仟伍佰贰拾叁元贰角叁分
以上是关于急求ios人民币大小写转换代码(将阿拉伯数字转换位中文大写,允许有两位小数)。的主要内容,如果未能解决你的问题,请参考以下文章