數字金額大小寫轉換
有很多時候列印憑據的時候需要實現金額大寫,例如
有多種寫法來實現
例如一下幾種
CREATE OR REPLACE FUNCTION chinese_number_program(p_input FLOAT) RETURN VARCHAR2 AS TYPE typ_money IS TABLE OF VARCHAR2(20); c_numbers typ_money := typ_money('零', '壹', '貳', '叄', '肆', '伍', '陸', '柒', '捌', '玖'); c_unit typ_money := typ_money('分', '角', '圓', '拾', '佰', '仟', '萬', '拾', '佰', '仟', '億', '拾', '佰', '仟', '兆', '拾', '佰', '仟'); v_array_money typ_money := typ_money(); chinese_number VARCHAR2(30); RESULT VARCHAR2(1000); v_number INTEGER; v_number_element INTEGER; i INT; BEGIN IF (p_input >= power(10, 16)) THEN RESULT := '超出計算範圍'; RETURN RESULT; END IF; v_number := round(p_input * 100); i := 1; v_array_money.extend(1); v_array_money(v_array_money.count) := '整'; WHILE v_number > 0 LOOP v_number_element := MOD(v_number, 10); IF (v_number_element = 0) THEN IF i IN (3, 7, 11, 15) THEN chinese_number := c_unit(i); ELSE chinese_number := c_numbers(v_number_element + 1); END IF; ELSE chinese_number := c_numbers(v_number_element + 1) || c_unit(i); END IF; CASE WHEN chinese_number = '零' THEN IF (v_array_money(v_array_money.count) NOT IN ('整', '零', '圓', '萬', '億', '兆')) THEN v_array_money.extend(1); v_array_money(v_array_money.count) := chinese_number; END IF; WHEN chinese_number LIKE '%億' THEN IF (v_array_money(v_array_money.count) IN ('萬')) THEN v_array_money(v_array_money.count) := chinese_number; ELSE v_array_money.extend(1); v_array_money(v_array_money.count) := chinese_number; END IF; WHEN chinese_number LIKE '%兆' THEN IF (v_array_money(v_array_money.count) IN ('萬', '億')) THEN v_array_money(v_array_money.count) := chinese_number; ELSE v_array_money.extend(1); v_array_money(v_array_money.count) := chinese_number; END IF; ELSE v_array_money.extend(1); v_array_money(v_array_money.count) := chinese_number; END CASE; v_number := floor(v_number / 10); i := i + 1; END LOOP; FOR i IN v_array_money.first .. v_array_money.last LOOP RESULT := v_array_money(i) || RESULT; END LOOP; RETURN RESULT; END;
#import <Foundation/Foundation.h> #import <stdio.h> void print( NSArray *array ) { int i; for (i=0;i<[array count];i++) { NSLog(@"%@",[array objectAtIndex:i]); } } void print2( NSArray *array ) { NSEnumerator *enumerator = [array objectEnumerator]; id obj; while ( obj = [enumerator nextObject] ) { printf( "%s\n", [[obj description] cString] ); } } void print3( NSArray *array ) { id obj; NSLog(@"new array is "); for (obj in array) { NSLog(@"%@",obj); } } NSString * printByLine( NSArray *array ) { id obj; NSMutableString * oneLine; oneLine=[NSMutableString stringWithCapacity:100]; NSString * oneString; for (obj in array) { oneString=[obj copy]; //[oneLine appendString:oneString]; [oneLine insertString:oneString atIndex:0]; // NSLog(@"xx= %@,%d,%d",oneLine,oneLine,oneString); } return oneLine; } int main() { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; //NSArray *arr_numbers = [[NSArray alloc] initWithObjects:@"Áã", @"Ò¼", @"·¡", @"Èþ", @"ËÁ", @"Îé", @"½", @"Æâ", @"°Æ", @"¾Á", nil]; NSArray *arr_numbers = [[NSArray alloc] initWithObjects:@"Zero", @"One", @"Two", @"Three", @"Four", @"Five", @"Six", @"Seven", @"Eight", @"Nine", nil]; //NSArray *arr_unit = [[NSArray alloc] initWithObjects:@"·Ö", @"½Ç", @"Ô²", @"Ê°", @"°Û", @"Ǫ", @"Íò", @"Ê°", @"°Û", @"Ǫ", @"ÒÚ", @"Ê°", @"°Û", @"Ǫ", @"Õ×", @"Ê°", @"°Û", @"Ǫ",nil]; NSArray *arr_unit = [[NSArray alloc] initWithObjects:@"F", @"J", @"Yuan", @"S", @"B", @"Q", @"W", @"S", @"B", @"Q", @"Yi", @"S", @"B", @"Q", @"Z", @"S", @"B", @"Q",nil]; NSMutableArray * mutable_money = [[NSMutableArray alloc] init]; NSSet * set_special_number=[[NSSet alloc] initWithObjects:@"Zheng",@"Zero",@"Yuan",@"W",@"Yi",@"Z"]; //print(arr_numbers); // print2(arr_numbers); // print3(arr_unit); float p_input_number; int input_number; int input_number_element; int i=0; NSString * chinese_number; NSString * result; p_input_number=1008.20; if (p_input_number>9999999) { result
[email protected]"out of maximize range"; NSLog(@"%@",result); return 0; } input_number=p_input_number*100; [mutable_money addObject:@"Zheng"]; //[[chinese_number alloc] init]; while (input_number>0) { input_number_element=input_number%10; if(input_number_element==0) { if (i == 2 || i==6 || i==10 || i==14) { chinese_number=[arr_unit objectAtIndex:i]; } else { chinese_number=[arr_numbers objectAtIndex:input_number_element]; } } else { chinese_number=[[arr_numbers objectAtIndex:input_number_element] stringByAppendingString:[arr_unit objectAtIndex:i]]; } // NSLog(@"%@,%@,%@",chinese_number,[arr_numbers objectAtIndex:input_number_element],[arr_unit objectAtIndex:i]); // NSLog(@"%d,%d,%d",chinese_number,[arr_numbers objectAtIndex:input_number_element],[arr_unit objectAtIndex:i]); if ([chinese_number isEqualToString:@"Zero"]) { if (!([set_special_number containsObject:[mutable_money lastObject]])) { [mutable_money addObject:chinese_number]; //NSLog(@"zero is %@,%@,%@",chinese_number,[arr_numbers objectAtIndex:input_number_element],[arr_unit objectAtIndex:i]); } } else if ([chinese_number hasSuffix:@"Yi"]) { if ([[mutable_money lastObject] isEqualToString:@"W"]) { [mutable_money removeLastObject]; [mutable_money addObject:chinese_number]; } else { [mutable_money addObject:chinese_number]; } //NSLog(@"Yi is %@,%@,%@",chinese_number,[arr_numbers objectAtIndex:input_number_element],[arr_unit objectAtIndex:i]); } else { [mutable_money addObject:chinese_number]; //NSLog(@"Others is %@,%@,%@",chinese_number,[arr_numbers objectAtIndex:input_number_element],[arr_unit objectAtIndex:i]); } input_number=input_number/10; i++; } NSLog(@"%@",printByLine(mutable_money)); // free memory [arr_numbers release]; [arr_unit release]; [mutable_money release]; [pool release]; return 0; }
FUNCTION money_format_zhs(p_money_amount IN NUMBER) RETURN VARCHAR2 IS
c_money_amount VARCHAR2(20);
n_string VARCHAR2(40) := '壹貳叄肆伍陸柒捌玖';
l_string VARCHAR2(600);
n CHAR;
l_length NUMBER;
i NUMBER;
tmp NUMBER;
is_zero BOOLEAN;
z_count NUMBER;
l_money_amount NUMBER;
l_sign VARCHAR2(10);
BEGIN
l_money_amount := round(abs(p_money_amount),
2);
IF p_money_amount < 0 THEN
l_sign := '負';
ELSE
l_sign := '';
END IF;
tmp := l_money_amount * 100;
c_money_amount := rtrim(ltrim(to_char(tmp,
'999999999999999999')));
l_length := length(c_money_amount);
i := 0;
WHILE i < l_length
LOOP
i := i + 1;
n := substr(c_money_amount,
i,
1);
IF n <> '0' THEN
l_string := l_string || substr(n_string,
to_number(n),
1);
IF l_length - i = 1 THEN
l_string := l_string || '角';
END IF;
IF l_length - i = 0 THEN
l_string := l_string || '分';
END IF;
IF l_length > 4
AND l_length - i > 1 THEN
IF MOD(l_length - i - 1,
4) = 0 THEN
l_string := l_string || '仟';
END IF;
IF MOD(l_length - i,
4) = 0 THEN
l_string := l_string || '佰';
END IF;
IF MOD(l_length - i + 1,
4) = 0 THEN
l_string := l_string || '拾';
END IF;
ELSE
IF l_length - i = 3 THEN
l_string := l_string || '拾';
END IF;
END IF;
END IF;
IF n = '0' THEN
IF l_length - i IN (10,
6,
2,
0,
i) THEN
IF is_zero THEN
l_string := substr(l_string,
1,
length(l_string) - 1);
is_zero := FALSE;
END IF;
z_count := 0;
ELSE
IF z_count = 0 THEN
l_string := l_string || '零';
is_zero := TRUE;
END IF;
z_count := z_count + 1;
END IF;
ELSE
z_count := 0;
is_zero := FALSE;
END IF;
IF (l_length - i = 6 OR l_length - i = 14)
AND substr(c_money_amount,
i - 3,
4) <> '0000' THEN
l_string := l_string || '萬';
END IF;
IF l_length - i = 10 THEN
l_string := l_string || '億';
END IF;
IF l_length - i = 2 THEN
l_string := l_string || '圓';
END IF;
END LOOP;
l_string := l_string || '整';
l_string := l_sign || l_string;
RETURN l_string;
EXCEPTION
WHEN OTHERS THEN
RETURN(SQLERRM);
END;
FUNCTION money_format_us(p_money_amount IN NUMBER) RETURN VARCHAR2 IS
TYPE lt_array_type IS VARRAY(50) OF VARCHAR2(20); --一維陣列,字串型別
l_array lt_array_type := lt_array_type('ONE ',
'TWO ',
'THREE ',
'FOUR ',
'FIVE ',
'SIX ',
'SEVEN ',
'EIGHT ',
'NINE ',
'TEN ',
'ELEVEN ',
'TWELVE ',
'THIRTEEN ',
'FOURTEEN ',
'FIFTEEN ',
'SIXTEEN ',
'SEVENTEEN ',
'EIGHTEEN ',
'NINETEEN ',
'TWENTY ',
'THIRTY ',
'FORTY ',
'FIFTY ',
'SIXTY ',
'SEVENTY ',
'EIGHTY ',
'NINETY ',
'HUNDRED ',
'THOUSAND ',
'MILLION ',
'BILLION ');
c_money_amount VARCHAR2(14);
l_string VARCHAR2(600);
n CHAR;
l_pre_n CHAR;
l_length NUMBER;
i NUMBER;
tmp NUMBER;
l_decimal_flag VARCHAR2(1);
l_money_amount NUMBER;
l_sign VARCHAR2(10);
BEGIN
l_money_amount := round(abs(p_money_amount),
2);
IF p_money_amount < 0 THEN
l_sign := 'NEGATIVE ';
ELSE
l_sign := '';
END IF;
tmp := l_money_amount * 100;
c_money_amount := rtrim(ltrim(to_char(tmp,
'999999999999999999')));
l_length := length(c_money_amount);
i := 0;
WHILE i < l_length - 2
LOOP
i := i + 1;
IF MOD(l_length - 2 - i,
3) = 2 THEN
n := substr(c_money_amount,
i,
1);
IF n <> '0' THEN
l_string := l_string || l_array(to_number(n));
l_string := l_string || l_array(to_number(28));
END IF;
END IF;
IF MOD(l_length - 2 - i,
3) = 1 THEN
n := substr(c_money_amount,
i,
1);
IF n = '1' THEN
l_pre_n := n;
END IF;
IF n NOT IN ('0',
'1') THEN
l_string := l_string || l_array(to_number(n) + 18);
END IF;
END IF;
IF MOD(l_length - 2 - i,
3) = 0 THEN
IF nvl(l_pre_n,
'X') = '1' THEN
n := substr(c_money_amount,
i,
1);
l_string := l_string || l_array(to_number(l_pre_n || n));
l_pre_n := NULL;
ELSE
n := substr(c_money_amount,
i,
1);
IF n <> '0' THEN
l_string := l_string || l_array(to_number(n));
END IF;
END IF;
END IF;
IF l_length - i = 5
AND substr(c_money_amount,
i - 2,
3) <> '000' THEN
l_string := l_string || l_array(to_number(29));
END IF;
IF l_length - i = 8
AND substr(c_money_amount,
i - 2,
3) <> '000' THEN
l_string := l_string || l_array(to_number(30));
END IF;
IF l_length - i = 11 THEN
l_string := l_string || l_array(to_number(31));
END IF;
END LOOP;
n := substr(c_money_amount,
l_length - 1,
1);
IF n NOT IN ('0',
'1') THEN
l_decimal_flag := 'Y';
l_string := l_string || 'AND ';
l_string := l_string || l_array(to_number(n) + 18);
END IF;
IF n = '1' THEN
l_decimal_flag := 'Y';
l_string := l_string || 'AND ';
l_pre_n := n;
n := substr(c_money_amount,
l_length,
1);
l_string := l_string || l_array(to_number(l_pre_n || n));
ELSE
n := substr(c_money_amount,
l_length,
1);
IF n <> '0' THEN
IF nvl(l_decimal_flag,
'N') = 'N' THEN
l_string := l_string || 'AND ';
END IF;
l_decimal_flag := 'Y';
l_string := l_string || l_array(to_number(n));
END IF;
END IF;
IF l_decimal_flag = 'Y' THEN
l_string := l_string || 'CENTS ';
ELSE
l_string := l_string;
END IF;
l_string := l_sign || l_string || 'ONLY ';
RETURN l_string;
EXCEPTION
WHEN OTHERS THEN
RETURN(SQLERRM);
END;
相關推薦
js 數字金額大小寫轉換成中文大寫
function Arabia_to_Chinese(Num) { for(i=Num.length-1;i>=0;i--) { Num = Num.replace(",","")//替換tomoney()中的“,” Num = Num.rep
數字金額大小寫轉換
有很多時候列印憑據的時候需要實現金額大寫,例如 有多種寫法來實現 例如一下幾種 CREATE OR REPLACE FUNCTION chinese_number_program(p_input FLOAT) RETURN VARCHAR2 AS TYPE
金額大小寫轉換工具使用
import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.math.BigDecimal; import java.math.BigInteger; public class ChineseNumberUtil {
金額大小寫轉換
import java.util.Scanner; public class Money { public static void main(String[] args) { Scanner input=new Scanner(System.in); // 金額大小寫轉換 System.
4.8 數字金額大寫轉換 外掛 > 我的程式猿之路:第三十八章
1 <script> 2 3 /** 數字金額大寫轉換(可以處理整數,小數,負數) */ 4 function smalltoBIG(n) 5 { 6 var fraction = ['角', '分']; 7
java-數字金額大寫轉換
/** * 數字金額大寫轉換,思想先寫個完整的然後將如零拾替換成零 要用到正則表示式 */ public static String digitUppercase(double n) { String fraction[] = {"角", "分"}; String
VB 金額大小寫轉換(兩種方法)
' 本模組生成漢字大寫的金額 'Option Explicit' 名稱: CCh ' 得到一位數字 N1 的漢字大寫 ' 0 返回 ""Function CCh(N1) As String Select Case N1Case 0CCh = "零"Case 1CCh = "壹"Case 2CCh = "貳"C
金額大小寫轉換正則
/// <summary> /// 人民幣金額小寫轉大寫 /// </summary> /// <param name="moneyAmount">小寫金額</param> /// &
js數字金額大寫轉換
<script> /** 數字金額大寫轉換(可以處理整數,小數,負數) */ var digitUppercase = function(n) { var fraction = ['角', '分']; var
數字轉換成中文大小寫、金額大小寫
ble clas upper subst sum turn remove 大小 spl 將數字轉換成中文大小寫、金額大小寫 /// <summary> /// 將數字轉換成中文大寫 /// <
SSRS 實現數字金額轉換為中文大寫漢字
and pre lds 2.0 ber 部分 ima 中文 res 比如: 金額=49,701,120.00,將其轉換為“肆仟玖佰柒拾萬壹仟壹佰貳拾元整”;金額 289,546.52 ,轉換為 “貳拾捌萬玖仟伍佰肆拾陸元伍角貳分”。 解決方法:添加VB的轉換函數寫在CO
數字金額轉換為漢字金額
個數字 都去 漢字 pen new lose one ron 精度 數字金額轉換為漢字金額 一、源代碼:DoubleMoneyToChineseMoney.java 1 package cn.com.zfc.example; 2 3 import java.
猜數字小遊戲+折半查詢法(二分法)+三次密碼輸入+字母大小寫轉換
猜數字小遊戲: #include<stdio.h> #include<time.h> #include<stdlib.h> /* 猜數字小遊戲 */ int menu() { printf("**********1.開始遊戲**********\n
JS實現將數字金額轉換為大寫人民幣漢字的方法
function convertCurrency(money) { //漢字的數字 var cnNums = new Array('零', '壹', '貳', '叄', '肆', '伍', '陸', '柒', '捌', '玖'); //基本單位 var cnIntRadice = n
人民幣大小寫轉換(阿拉伯數字和漢字轉換)
最近在網上看到一個關於數字轉換人民幣大寫的演算法的一篇部落格,很好,就收藏了,演算法直接copy原作者的。自己做了一點小改動: 1.以CString代替,封裝成類。 2.修復超
[演算法題] 人民幣大小寫轉換(阿拉伯數字和漢字轉換)
在一次面試中遇到一個有意思的小演算法題:要求將阿拉伯數字轉為漢字顯示出來(包含單位)。 當時雖然實現出來,但是程式碼寫的有點凌亂。所以回家後,重新整理了一下。 這個演算法有幾個小的注意點: 1、中文字元佔兩個位元組,所以如果用C語言實現,需要用char陣列的形式儲存單個漢字。 2、如果數字中出現連
JS數字金額轉換為貨幣漢字形式
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePat
在fastreport裡轉換金額大小寫
在fastreport的pascalscript裡面我沒有搞明白怎麼呼叫sysutil……所以寫了一個比較笨辦法的轉換函式 不過好處是應該適用於所有版本——因為使用的是最基礎的東西…… 只能轉換小於一萬億的數字,更大的得改寫一下。 function MoneyToCha
c++ 大小寫轉換&&字元轉數字
大小寫轉換&&字元轉數字,實驗筆記。 int main() { //其實就是對ASCii表的操作 string s; char a = 'a';
java實現數字金額轉換中文大寫金額
直接貼程式碼吧! public class CnNumberUtils { private final static Logger logger = LoggerFactory.getLogger(CnNumberUtils.class);