| |

VerySource

 Forgot password?
 Register
Search
View: 683|Reply: 3

RMB figures are converted into text. For example, how can 1235 output 1,235 yuan?

[Copy link]

3

Threads

10

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-1-20 12:40:01
| Show all posts |Read mode
It feels very simple, but I have no ideas. .
Reply

Use magic Report

1

Threads

20

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-1-28 22:36:02
| Show all posts
Someone sent it before ~

import java.awt. *;
import java.awt.event. *;

class Test
{
    public static void main (String [] args)
    {
        String num = "零 一 贰 三 肆 伍 陆 柒 捌 玖";
        String dw = "Around a hundred trillion yuan";
        String m = "30020.23";
        String mm [] = null;
        mm = m.split ("\\.");
        String money = mm [0];

        String result = num.charAt (Integer.parseInt ("" + mm [1] .charAt (0))) +
            "Corner" +
            num.charAt (Integer.parseInt ("" + mm [1] .charAt (1))) + "minute";

        for (int i = 0; i <money.length (); i ++)
        {
            String str = "";
            int n = Integer.parseInt (money.substring (money.length ()-i-1,
                money.length ()-i));
            str = str + num.charAt (n);
            if (i == 0)
            {
                str = str + dw.charAt (i);
            }
            else if ((i + 4)% 8 == 0)
            {
                str = str + dw.charAt (4);
            }
            else if (i% 8 == 0)
            {
                str = str + dw.charAt (5);
            }
            else
            {
                str = str + dw.charAt (i% 4);
            }
            result = str + result;
        }
        result = result.replaceAll ("zero ([^ 圆] {1})", "zero");
        result = result.replaceAll ("zero +", "zero");
        result = result.replaceAll ("zero circle", "circle");
        System.out.println (result);

    }
}
Reply

Use magic Report

0

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-29 17:00:01
| Show all posts
<script language = "javascript">
var strArray = new Array ();
strArray [0] = "Meta"
strArray [1] = "Ten"
strArray [2] = "hundred"
strArray [3] = "Thousands"

var str = "1235";

var len = str.length;

var ss = "";
for (i = 1; i <= len; i ++) {
ss + = str.substring (i-1, i) + strArray [len-i];
}
alert (ss);
</ script>
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-31 16:09:01
| Show all posts
1. (C #):
// Add to the definition part of the class
private static string [] cstr = {"zero", "one", "贰", "three", "three", "wu", "lu", "柒", "捌", "玖"};
private static string [] wstr = {"", "", "pick up", "bai", "仟", "wan", "pick up", "bai", "仟", "billion", "pick up, "百", "仟"};
// A string whose number must be within a 12-digit integer
// Call method such as: Label1.Text = ConvertInt ("numeric string");

public string ConvertInt (string str)
{
int len ​​= str.Length;
int i;
string tmpstr, rstr;
rstr = "";
for (i = 1; i <= len; i ++)
{
tmpstr = str.Substring (len-i, 1);
rstr = string.Concat (cstr [Int32.Parse (tmpstr)] + wstr [i], rstr);
}
rstr = rstr.Replace ("pick up", "pick up");
rstr = rstr.Replace ("Zero Pickup", "Zero");
rstr = rstr.Replace ("零 百", "零");
rstr = rstr.Replace ("零 仟", "zero");
rstr = rstr.Replace ("zero million", "million");
for (i = 1; i <= 6; i ++)
rstr = rstr.Replace ("zero zero", "zero");
rstr = rstr.Replace ("Zero million", "Zero");
rstr = rstr.Replace ("billion", "billion");
rstr = rstr.Replace ("zero zero", "zero");
rstr + = "rounded";
return rstr;
}


 

2.
ASP code to convert case amount
<%
dim a 'Amount to be converted to upper case
dim atoc 'converted value
Dim String1 'as defined below
Dim String2 'as defined below
Dim String3 'The value taken from the original A value
Dim I 'loop variable
Dim J 'A value multiplied by 100 string length
Dim Ch1 'Numbers in Chinese
Dim Ch2 'Digital Chinese Characters
Dim nZero 'is used to calculate the continuous zero value is several

String1 = "零 一 贰 三 肆 伍 陆 柒 捌 玖"
String2 = "One hundred million dollars One hundred million dollars One hundred million dollars One thousand yuan points"
nZero = 0

If InStr (1, CStr (a * 100), ".") <> 0 Then
err.Raise 5000,, "This function (AtoC ()) can only convert numbers with less than two decimal places!"
End If

J = Len (CStr (a * 100))
String2 = Right (String2, J) 'Remove the value of STRING2 with the corresponding number of digits

For I = 1 To J
String3 = Mid (a * 100, I, 1) 'Remove the value of a bit to be converted

If I <> (J-3) + 1 And I <> (J-7) + 1 And I <> (J-11) + 1 And I <> (J-15) + 1 Then
If String3 = 0 Then
Ch1 = ""
Ch2 = ""
nZero = nZero + 1
ElseIf String3 <> 0 And nZero <> 0 Then
Ch1 = "zero"&Mid (String1, clng (String3) + 1, 1)
Ch2 = Mid (String2, I, 1)
nZero = 0
Else
Ch1 = Mid (String1, clng (String3) + 1, 1)
Ch2 = Mid (String2, I, 1)
nZero = 0
End If
Else 'This bit is the key bit of trillion, billion, million, yuan, etc.
If String3 <> 0 And nZero <> 0 Then
Ch1 = "zero"&Mid (String1, clng (String3) + 1, 1)
Ch2 = Mid (String2, I, 1)
nZero = 0
ElseIf String3 <> 0 And nZero = 0 Then
Ch1 = Mid (String1, clng (String3) + 1, 1)
Ch2 = Mid (String2, I, 1)
nZero = 0
ElseIf String3 = 0 And nZero> = 3 Then
Ch1 = ""
Ch2 = ""
nZero = nZero + 1
Else
Ch1 = ""
Ch2 = Mid (String2, I, 1)
nZero = nZero + 1
End If

If I = (J-11) + 1 Or I = (J-3) + 1 Then 'If the bit is a billion or a bit, you must write
Ch2 = Mid (String2, I, 1)
End If

End If
AtoC = AtoC&Ch1&Ch2

If I = J And String3 = 0 Then 'When the last digit (point) is 0, add "whole"
AtoC = AtoC&"Whole"
End If

Next
if a = 0 then
atoc = "零 元 整"
end if
%>


 

3.
<!-# include file = common.asp->
<%
dim tmpnum
'Lower case amount from the first page
tmpnum = request ("page1num")
'Call and display capitalized amount
response.write rmb (cdbl (tmpnum))
response.end
%>


common.asp
<%
Function rmb (num)

num = FormatNumber (num, 2)
Dim numList
Dim rmbList
Dim numLen
Dim numChar
Dim numstr
Dim n
Dim n1, n2
Dim hz
numList = "零 一 贰 三 肆 伍 陆 柒 捌 玖"
rmbList = "Diagonal Yuan Shi Bai Shi Wan Shi Bai Shi Wan Shi Bai Shi Wan Bai Shi Wan Wan"

If num> 9999999999999.99 Then
rmb = "Out of range RMB value"
Exit Function
End If

numstr = CStr (num * 100)
numLen = Len (numstr)
n = 1
Do While n <= numLen
numChar = CInt (Mid (numstr, n, 1))
n1 = Mid (numList, numChar + 1, 1)
n2 = Mid (rmbList, numLen-n + 1, 1)
If Not n1 = "zero" Then
hz = hz + CStr (n1) + CStr (n2)
Else
If n2 = "billion" Or n2 = "million" Or n2 = "yuan" Or n1 = "zero" Then
Do While Right (hz, 1) = "zero"
hz = Left (hz, Len (hz)-1)
Loop
End If
If (n2 = "billion" Or (n2 = "million" And Right (hz, 1) <> "billion") Or n2 = "yuan") Then
hz = hz + CStr (n2)
Else
If Left (Right (hz, 2), 1) = "zero" Or Right (hz, 1) <> "billion" Then
hz = hz + n1
End If
End If
End If
n = n + 1
Loop
Do While Right (hz, 1) = "zero"
hz = Left (hz, Len (hz)-1)
Loop
If Right (hz, 1) = "Yuan" Then
hz = hz + "whole"
End If
rmb = hz
End Function

%>


This version solves the problem that the decimal place cannot reach the point, and the processing method conforms to the accounting method!


 

4.
A completely error-free version of the amount of case conversion


<!-# include file = common.asp->
<%
dim tmpnum
'Lower case amount from the first page
tmpnum = request ("page1num")
'Call and display capitalized amount
response.write rmb (cdbl (tmpnum))
response.end
%>


A completely error-free version of the amount of case conversion


<!-# include file = common.asp->
<%
dim tmpnum
'Lower case amount from the first page
tmpnum = request ("page1num")
'Call and display capitalized amount
response.write rmb (cdbl (tmpnum))
response.end
%>


common.asp
<%
Function rmb (num)

num = FormatNumber (num, 2)
Dim numList
Dim rmbList
Dim numLen
Dim numChar
Dim numstr
Dim n
Dim n1, n2
Dim hz
numList = "零 一 贰 三 肆 伍 陆 柒 捌 玖"
rmbList = "Diagonal Yuan Shi Bai Shi Wan Shi Bai Shi Wan Shi Bai Shi Wan Bai Shi Wan Wan"

If num> 9999999999999.99 Then
rmb = "Out of range RMB value"
Exit Function
End If

numstr = CStr (num * 100)
numLen = Len (numstr)
n = 1
Do While n <= numLen
numChar = CInt (Mid (numstr, n, 1))
n1 = Mid (numList, numChar + 1, 1)
n2 = Mid (rmbList, numLen-n + 1, 1)
If Not n1 = "zero" Then
hz = hz + CStr (n1) + CStr (n2)
Else
If n2 = "billion" Or n2 = "million" Or n2 = "yuan" Or n1 = "zero" Then
Do While Right (hz, 1) = "zero"
hz = Left (hz, Len (hz)-1)
Loop
End If
If (n2 = "billion" Or (n2 = "million" And Right (hz, 1) <> "billion") Or n2 = "yuan") Then
hz = hz + CStr (n2)
Else
If Left (Right (hz, 2), 1) = "zero" Or Right (hz, 1) <> "billion" Then
hz = hz + n1
End If
End If
End If
n = n + 1
Loop
Do While Right (hz, 1) = "zero"
hz = Left (hz, Len (hz)-1)
Loop
If Right (hz, 1) = "Yuan" Then
hz = hz + "whole"
End If
rmb = hz
End Function

%>




5.
<% function Money (thenumber)
dim Money, i, String1, String2, length, checkp&acute; define variables
dim one (), onestr ()&acute; define array

String1 = "零 一 贰 三 肆 伍 陆 柒 捌 玖"
String2 = "One hundred million dollars, one hundred million dollars, one hundred million dollars, one hundred and twenty cents"

checkp = instr (thenumber, ".")&acute; determine whether it contains decimal places
if checkp <> 0 then
thenumber = replace (thenumber, ".", "")&acute; remove decimal places
end if

length = len (thenumber)&acute; Get data length
redim one (length-1)&acute; redefine array size
redim onestr (length-1)&acute; redefine array size

for i = 0 to length-1

one (i) = mid (thenumber, i + 1,1)&acute; get each digit
one (i) = mid (string1, one (i) +1,1)&acute; loop to get the uppercase corresponding to the number


if checkp = 0 then
&acute; data without decimals corresponding to the unit of number
onestr (i) = mid (string2,14-length + i, 1)
else
&acute; data containing decimals and its corresponding unit
onestr (i) = mid (string2,15-length + i + len (thenumber) -checkp, 1)
end if

one (i) = one (i)&onestr (i)&acute; combine numbers and units
next

Money = replace (join (one), "", "")&acute; Get all elements in the array and connect them
Money = replace (Money, "Zero", "Yuan")
Money = replace (Money, "Zero million", "Million")
Money = replace (Money, "billion", "billion")
Money = replace (Money, "零 仟", "零")
Money = replace (Money, "零 百", "零")
Money = replace (Money, "Zero Pickup", "Zero")

do while not instr (Money, "Zero Zero") = 0
Money = replace (Money, "zero zero", "zero")
loop

response.write Money&acute; show results
end function
%>
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list