SQL金额小写转大写

CREATE FUNCTION dbo.L2U(@n_LowerMoney numeric(15,2),@v_TransType int)
RETURNS VARCHAR(200) AS
BEGIN
Declare @v_LowerStr VARCHAR(200) -- 小写金额
Declare @v_UpperPart VARCHAR(200)
Declare @v_UpperStr VARCHAR(200) -- 大写金额
Declare @i_I int

set @v_LowerStr = LTRIM(RTRIM(ROUND(@n_LowerMoney,2))) --四舍五入为指定的精度并删除数据左右空格
set @i_I = 1
set @v_UpperStr = ''

while ( @i_I <= len(@v_LowerStr))
begin
select @v_UpperPart = case substring(@v_LowerStr,len(@v_LowerStr) - @i_I + 1,1)
WHEN '.' THEN '元'
WHEN '0' THEN '零'
WHEN '1' THEN '壹'
WHEN '2' THEN '贰'
WHEN '3' THEN '叁'
WHEN '4' THEN '肆'
WHEN '5' THEN '伍'
WHEN '6' THEN '陆'
WHEN '7' THEN '柒'
WHEN '8' THEN '捌'
WHEN '9' THEN '玖'
END
+
case @i_I
WHEN 1 THEN '分'
WHEN 2 THEN '角'
WHEN 3 THEN ''
WHEN 4 THEN ''
WHEN 5 THEN '拾'
WHEN 6 THEN '佰'
WHEN 7 THEN '仟'
WHEN 8 THEN '万'
WHEN 9 THEN '拾'
WHEN 10 THEN '佰'
WHEN 11 THEN '仟'
WHEN 12 THEN '亿'
WHEN 13 THEN '拾'
WHEN 14 THEN '佰'
WHEN 15 THEN '仟'
WHEN 16 THEN '万'
ELSE ''
END
set @v_UpperStr = @v_UpperPart + @v_UpperStr
set @i_I = @i_I + 1
end

if ( 0 = @v_TransType)
begin
set @v_UpperStr = REPLACE(@v_UpperStr,'零拾','零')
set @v_UpperStr = REPLACE(@v_UpperStr,'零佰','零')
set @v_UpperStr = REPLACE(@v_UpperStr,'零仟','零')
set @v_UpperStr = REPLACE(@v_UpperStr,'零零零','零')
set @v_UpperStr = REPLACE(@v_UpperStr,'零零','零')
set @v_UpperStr = REPLACE(@v_UpperStr,'零角零分','整')
set @v_UpperStr = REPLACE(@v_UpperStr,'零分','整')
set @v_UpperStr = REPLACE(@v_UpperStr,'零角','零')
set @v_UpperStr = REPLACE(@v_UpperStr,'零亿零万零元','亿元')
set @v_UpperStr = REPLACE(@v_UpperStr,'亿零万零元','亿元')
set @v_UpperStr = REPLACE(@v_UpperStr,'零亿零万','亿')
set @v_UpperStr = REPLACE(@v_UpperStr,'零万零元','万元')
set @v_UpperStr = REPLACE(@v_UpperStr,'万零元','万元')
set @v_UpperStr = REPLACE(@v_UpperStr,'零亿','亿')
set @v_UpperStr = REPLACE(@v_UpperStr,'零万','万')
set @v_UpperStr = REPLACE(@v_UpperStr,'零元','元')
set @v_UpperStr = REPLACE(@v_UpperStr,'零零','零')
end

-- 对壹元以下的金额的处理
if ( '元' = substring(@v_UpperStr,1,1))
begin
set @v_UpperStr = substring(@v_UpperStr,2,(len(@v_UpperStr) - 1))
end

if ( '零' = substring(@v_UpperStr,1,1))
begin
set @v_UpperStr = substring(@v_UpperStr,2,(len(@v_UpperStr) - 1))
end

if ( '角' = substring(@v_UpperStr,1,1))
begin
set @v_UpperStr = substring(@v_UpperStr,2,(len(@v_UpperStr) - 1))
end

if ( '分' = substring(@v_UpperStr,1,1))
begin
set @v_UpperStr = substring(@v_UpperStr,2,(len(@v_UpperStr) - 1))
end

if ('整' = substring(@v_UpperStr,1,1))
begin
set @v_UpperStr = '零元整'
end
return @v_UpperStr
END
GO

--select dbo.L2U(0,1),dbo.L2U(010.1,0)

SQL金额小写转大写

时间: 2024-10-10 07:20:41

SQL金额小写转大写的相关文章

JS函数实现金额小写转大写

止乎于分享! 1 ///<summery>小写金额转化大写金额</summery> 2 function AmountLtoU(amount) { 3 if (isNaN(amount) || amount >= 1000000000000) return "无效金额!"; //数值最大不超过1万亿 4 var sPrefix = amount < 0 ? "(负)" : ""; //将负号‘-’显示成汉字‘(

[转] 金额小写变大写

1 /// <summary> 2 /// 金额小写变大写 3 /// </summary> 4 /// <param name="smallnum"></param> 5 /// <returns></returns> 6 public static string gMoney(decimal smallnum) 7 { 8 string cmoney , cnumber, cnum, cnum_end,cmon

C#金额小写转大写

public string ConvertMoney(decimal Money) { //金额转换程序 string MoneyNum = "";//记录小写金额字符串[输入参数] string MoneyStr = "";//记录大写金额字符串[输出参数] string BNumStr = "零壹贰叁肆伍陆柒捌玖";//模 string UnitStr = "万仟佰拾亿仟佰拾万仟佰拾圆角分";//模 MoneyNum =

js 金额小写转换为大写

<script> jQuery(document).ready(function () { //当金额文本框失去焦点时,自动将数字转化为大写填充到 大写的文本框中 $("#Amount").blur(function () { var amount = $("#Amount").val(); amount = AmountLtoU(amount); $("#CapitalAmount").val(amount); }); }); fu

C#金额小写转换为大写

//传入需要转换的金额(字符串) public static string MoneyToChinese(string strAmount)     { string functionReturnValue = null; bool IsNegative = false; // 是否是负数 if (strAmount.Trim().Substring(0, 1) == "-")         { // 是负数则先转为正数 strAmount = strAmount.Trim().Re

Python TIPS上一道关于人民币金额小写转大写的题

人民币金额打印 题目链接:here.我发现我写的好复杂,但万幸编码还算符合人类,看了其他答案,感觉都是天书. #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2017-06-09 # @Author : Bob Liao ([email protected]) # @Link : https://github.com/coderchaser # @Version : python3.4 #创建大小写转换字典 num_dic={ #

SQL函数:小写金额转换成大写

/********************************************************作者:版本:1.0创建时间:20020227修改时间:功能:小写金额转换成大写参数:n_LowerMoney 小写金额v_TransType 种类 -- 1: directly translate, 0: read it in words 输出:大写金额********************************************************/if exists

金额小写转中文大写类

using System; using System.Collections.Generic; using System.Text; namespace Class_ZhH { /// <summary> /// 金额小写转中文大写类(附带一个数字转大写). /// 整数支持到万亿:小数部分支持到分(超过两位将进行Banker舍入法处理) /// </summary> public class NumGetString { private static String[] Ls_Sh

小写金额转换成大写 - 函数脚本

原文:小写金额转换成大写 - 函数脚本 /********************************************************作者:版本:创建时间:修改时间:功能:小写金额转换成大写参数:输出:大写金额********************************************************/ CREATE FUNCTION [dbo].[f_num_chn] (@num numeric(14,2))RETURNS varchar(100) WI