zoukankan      html  css  js  c++  java
  • 程序员笔试题 将人民币金额转换成大写的金额

    提供两种方法:
    //////////////////////////////////////////////////////////////////////
    //将钱数转化为大写
    //////////////////////////////////////////////////////////////////////
    constant string ls_bit = "万仟佰拾亿仟佰拾万仟佰拾元角分"
    constant string ls_num = "壹贰叁肆伍陆柒捌玖"
    long lmax = len( ls_bit ) + 1
    string ls_je, ls_dw, ls_result = ''''
    long ll_len, i, k
    ls_je = string( data, "#############.00" )
    ll_len = len( ls_je ) - 1
    ls_je = replace( ls_je, ll_len - 1, 1, '''' )
    for i = ll_len to 1 step -1
    lmax -= 2
    ls_dw = mid( ls_bit, lmax, 2 )
    k = long( mid( ls_je, i, 1 ) )
    if k = 0 then
    choose case ls_dw
    case ''元'',''万'',''亿''
    ls_result = ls_dw + ls_result
    case ''分''
    ls_result = ''整''
    case ''角''
    if ls_result <> ''整'' then ls_result = ''零'' + ls_result
    case else
    choose case left( ls_result, 2 )
    case ''万'', ''亿'', ''元'', ''零''
    case else
    ls_result = ''零'' + ls_result
    end choose
    end choose
    else
    ls_result = mid( ls_num, k * 2 - 1, 2 ) + ls_dw + ls_result
    end if
    next
    return ls_result

    --------------------------------------------------------
    //入口参数:DECIMAL numb
    INTEGER i //循环变量
    STRING s_numb //以字符串表示
    STRING s_money
    INTEGER i1
    s_numb = String(numb,"########.00")
    IF Len(s_numb) < 11 THEN s_numb = Space(11-len(s_numb))+s_numb
    i = 1
    s_money = ""
    //去掉前导空格
    DO WHILE i<8 AND Mid(s_numb,i,1) = " "
    i ++
    LOOP

    i1 = 11 - i + 1

    INTEGER digit
    DO WHILE i<=4
    digit = Integer(Mid(s_numb,i,1))
    IF digit = 0 THEN
    DO WHILE i<=4
    digit = Integer(Mid(s_numb,i,1))
    IF digit <>0 THEN exit
    i ++
    LOOP
    IF i<=4 THEN s_money += "零"
    ELSE
    s_money += Mid("壹贰叁肆伍陆柒捌玖",digit*2-1,2) +&
    Mid("仟佰拾万",i*2-1,2)
    i ++
    END IF
    LOOP

    IF i1 >= 8 THEN
    IF Integer(Mid(s_numb,4,1)) = 0 THEN s_money += "万"
    END IF

    DO WHILE i<=8
    digit = Integer(Mid(s_numb,i,1))
    IF digit = 0 THEN
    DO WHILE i<=8
    digit = Integer(Mid(s_numb,i,1))
    IF digit<>0 THEN exit
    i ++
    LOOP
    IF i<=8 THEN
    s_money += "零"
    ELSE
    IF Integer(Mid(s_numb,1,8)) <> 0 THEN
    s_money += "元"
    IF Integer(Mid(s_numb,11,1))<>0 THEN s_money += "零"
    END IF
    END IF
    END IF
    IF digit <> 0 THEN
    s_money += Mid("壹贰叁肆伍陆柒捌玖",digit*2-1,2) + &
    Mid("仟佰拾万仟佰拾元",i*2-1,2)
    END IF
    i ++
    LOOP

    digit = Integer(Mid(s_numb,10,1))
    IF digit<>0 THEN
    s_money += Mid("壹贰叁肆伍陆柒捌玖",digit*2-1,2) + "角"
    ELSE
    IF Integer(Mid(s_numb,11,1))<>0 AND Integer(Mid(s_numb,1,9)) <> 0 THEN
    s_money += "零"
    END IF
    END IF

    digit = Integer(Mid(s_numb,11,1))
    IF digit <> 0 THEN
    s_money += Mid("壹贰叁肆伍陆柒捌玖",digit*2-1,2) + "分"
    ELSE
    IF Len(Trim(s_money)) <> 0 THEN s_money += "整"
    END IF

    RETURN s_money

  • 相关阅读:
    Golang结构体序列化与反序列化时默认值的问题
    Golang在函数中给结构体对象赋值的一个坑
    Go出现panic的场景
    Redis内存使用率增长的一些解决思路
    「转」50个Go新手容易犯的错误
    关系型数据库跨时区查询简介
    Golang中append与copy内置函数介绍
    实践案例1利用低代码开发平台Odoo快速构建律师事务所管理系统
    自助分析工具Power BI的简介和应用
    一个开源免费高颜值的轻量级商业智能BI平台Superset 介绍
  • 原文地址:https://www.cnblogs.com/ywqu/p/974206.html
Copyright © 2011-2022 走看看