金额转换为英文

Function ConvertCurrencyToEnglish(ByVal MyNumber)
         Dim
Temp
         Dim Dollars, Cents
         Dim DecimalPlace, Count

ReDim Place(9) As String
         Place(2) = " Thousand
"
         Place(3) = " Million "
         Place(4) = " Billion
"
         Place(5) = " Trillion "

‘ Convert MyNumber to a string, trimming extra spaces.
        
MyNumber = Trim(Str(Round(MyNumber, 2)))

‘ Find decimal place.
         DecimalPlace = InStr(MyNumber,
".")

‘ If we find decimal place...
         If DecimalPlace > 0
Then
            ‘ Convert cents
            Temp = Left(Mid(MyNumber,
DecimalPlace + 1) & "00", 2)
            Cents = ConvertTens(Temp)

‘ Strip off cents from remainder to convert.
           
MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
         End If

Count = 1
         Do While MyNumber <> ""
            ‘
Convert last 3 digits of MyNumber to English dollars.
            Temp =
ConvertHundreds(Right(MyNumber, 3))
            If Temp <> "" Then
Dollars = Temp & Place(Count) & Dollars
            If Len(MyNumber)
> 3 Then
               ‘ Remove last 3 converted digits from
MyNumber.
               MyNumber = Left(MyNumber, Len(MyNumber) -
3)
            Else
               MyNumber = ""
            End
If
            Count = Count + 1
         Loop

‘ Clean up dollars.
         Select Case Dollars
           
Case ""
               Dollars = "No Dollars"
            Case
"One"
               Dollars = "One Dollar"
            Case
Else
               Dollars = Dollars & " Dollars"
         End
Select

‘ Clean up cents.
         Select Case Cents
            Case
""
               Cents = " Only"
            Case "One"
              
Cents = " And One Cent"
            Case Else
               Cents = " And
" & Cents & " Cents"
         End Select

ConvertCurrencyToEnglish = Dollars & Cents
      End
Function

Private Function ConvertHundreds(ByVal MyNumber)
         Dim Result
As String

‘ Exit if there is nothing to convert.
         If Val(MyNumber)
= 0 Then Exit Function

‘ Append leading zeros to number.
         MyNumber = Right("000"
& MyNumber, 3)

‘ Do we have a hundreds place digit to convert?
         If
Left(MyNumber, 1) <> "0" Then
            If Right("000" &
MyNumber, 2) <> 0 Then
            Result = ConvertDigit(Left(MyNumber,
1)) & " Hundred and "
            Else
            Result =
ConvertDigit(Left(MyNumber, 1)) & " Hundred "
            End
If
        End If

‘ Do we have a tens place digit to convert?
         If
Mid(MyNumber, 2, 1) <> "0" Then
            Result = Result &
ConvertTens(Mid(MyNumber, 2))
         Else
            ‘ If not, then
convert the ones place digit.
            Result = Result &
ConvertDigit(Mid(MyNumber, 3))
         End If

ConvertHundreds = Trim(Result)
      End Function

Private Function ConvertTens(ByVal MyTens)
         Dim Result As
String

‘ Is value between 10 and 19?
         If Val(Left(MyTens, 1)) =
1 Then
            Select Case Val(MyTens)
               Case 10: Result
= "Ten"
               Case 11: Result = "Eleven"
               Case 12:
Result = "Twelve"
               Case 13: Result =
"Thirteen"
               Case 14: Result = "Fourteen"
               Case
15: Result = "Fifteen"
               Case 16: Result =
"Sixteen"
               Case 17: Result = "Seventeen"
               Case
18: Result = "Eighteen"
               Case 19: Result =
"Nineteen"
               Case Else
            End Select
        
Else
            ‘ .. otherwise it‘s between 20 and 99.
            Select
Case Val(Left(MyTens, 1))
               Case 2: Result =
"Twenty"
               Case 3: Result = "Thirty"
               Case 4:
Result = "Forty"
               Case 5: Result = "Fifty"
              
Case 6: Result = "Sixty"
               Case 7: Result =
"Seventy"
               Case 8: Result = "Eighty"
               Case 9:
Result = "Ninety"
               Case Else
            End Select

‘ Convert ones place digit.
            If Val(Right(MyTens,
1)) = 0 Then
            Result = Result & " " &
ConvertDigit(Right(MyTens, 1))
            Else
            Result =
Result & "-" & ConvertDigit(Right(MyTens, 1))
            End
If
        End If

ConvertTens = Result
     End Function

Private Function ConvertDigit(ByVal MyDigit)
         Select Case
Val(MyDigit)
            Case 1: ConvertDigit = "One"
            Case 2:
ConvertDigit = "Two"
            Case 3: ConvertDigit =
"Three"
            Case 4: ConvertDigit = "Four"
            Case 5:
ConvertDigit = "Five"
            Case 6: ConvertDigit = "Six"
           
Case 7: ConvertDigit = "Seven"
            Case 8: ConvertDigit =
"Eight"
            Case 9: ConvertDigit = "Nine"
            Case Else:
ConvertDigit = ""
         End Select
      End Function

时间: 2024-10-27 14:15:07

金额转换为英文的相关文章

把int型非负数转换为英文

数字转换为英文 输入为int型非负数,最大值为2^31 - 1 = 2 147 483 647 输出为String英文,最大输出为Two Billion One Hundred Forty Seven Million Four Hundred Eighty Three Thousand Six Hundred Forty Seven 输出要求每个单词首字母大写,之间用空格隔开,不需要用“and”做连词 例如: 123 -> "One Hundred Twenty Three" 1

人民币 小写金额转换为大写金额

### 人民币 小写金额转换为大写金额 标签(空格分隔): 人民币 小写金额转换为大写金额 --- jsp:```div class="form-group"><label class="col-sm-4 control-label">合计人民币金额(小写):</label><div class="col-sm-7"><input id="totalRmbLower" type=

ORACLE中将数字转换为英文

SELECT LEVEL, to_char(to_date(LEVEL,'J'),'Jsp') FROM dual CONNECT BY LEVEL <= 1000 运行结果如下图所示:   说明: TO_CHAR(aDate,'JSP')是指日期aDate距离JULIAN日期的第一天即4712-01-01BC的天数,也就是从公元前4712年的1月1号到aDate这个日期的天数的英文拼写. JULIAN日期的范围是公元前4712-01-01到公元9999-01-01.期间的天数是我们能够拼写的最

C#把金额转换为汉字表达式

/* 创建者:菜刀居士的博客 * 创建日期: 2014年09月04号 * 功能:Money类型转换 * */ namespace Net.String.ConsoleApplication { using System; using System.Collections.Generic; public class MoneyHelper { public static string[] chineseDigits = new string[] { "零", "壹",

汉字首字首拼转换为英文字母

PHP网站,我们经常会遇到按照汉字的首拼排序,如城市,如分类等,那么我们就需要把首字首拼转换为英文字母,下面的函数就可以帮我们实现: function getFristchar($str) { if(empty($str)){return '';} $fchar=ord($str{0}); if($fchar>=ord('A')&&$fchar<=ord('z')) return strtoupper($str{0}); //ord()返回ASC码 $s1=iconv('UTF

C#:小写金额转换为大写

#region 小写金额转换为大写 public static string CurrToChnNum(double Currnum) { string sResult = ""; if (Math.Abs(Currnum) < 1e-20) return "零圆整"; if (Currnum < 1e-20) sResult = "负"; sResult = sResult + StringToChnNum(Math.Abs(Mat

Oracle 小写金额转换为大写

在开发EBS的合同报表打印的时候需要将小写金额转换为大写. 如下是本人自己写的转换函数. 主要思路:先获取小数点位置,在区分整数与小数点处理,根据位数和数字组合读取金额. 最后再处理特殊显示部分. /******************************************************************* *  FUNCTION get_big_amount 数字金额转换为大写 *  p_amount 输入数据金额 *  返回大写金额,位数 :千亿----厘 ****

金额转换为自定义字符串

import java.math.BigDecimal; import java.math.RoundingMode; import java.text.DecimalFormat; public final class AmountUtil { private static DecimalFormat LIMIT_AMOUNT_FORMAT = new DecimalFormat("#.00"); static { LIMIT_AMOUNT_FORMAT.setRoundingMod

SSRS 实现数字金额转换为中文大写汉字

比如: 金额=49,701,120.00,将其转换为"肆仟玖佰柒拾万壹仟壹佰贰拾元整":金额 289,546.52 ,转换为 "贰拾捌万玖仟伍佰肆拾陆元伍角贰分". 解决方法:添加VB的转换函数写在CODE里,然后在表达式里调用自定义函数转换. 如:增加两个占位符表达式,如小数位为0时表达式2添加"整", 表达式1=Code.GetCnString(Fields!Amount.Value) 表达式2=IIF(Fields!Amount.Value