Если вы используете SQL Server для возврата вашего набора данных, то вы можете использовать следующую функцию
CREATE FUNCTION [dbo].[udf_CurrencyToWords] (@Input numeric(15,2),@Currency tinyint)
RETURNS varchar (8000)
AS
BEGIN
DECLARE @CharInput char(15)
--Pad the input
SET @CharInput = RIGHT('0000000000000' + convert(varchar(15),@Input),15)
DECLARE @Counter tinyint
SET @Counter = 1
DECLARE @InputSub varchar(3)
DECLARE @Group tinyint
DECLARE @Output varchar (8000)
--Get words for each group with some logic for concatenation
WHILE @Counter <= len(@CharInput)-2
BEGIN
SET @InputSub = replace(substring(@CharInput,@Counter,3),'.','')
SET @Group = (len(@CharInput)-@Counter+1)/3
SET @Output =
ISNULL(@Output,'')
+ CASE
WHEN (@Group = 1 AND @InputSub <> 0 AND @Input >= 1.00) OR (@Group = 2 AND @InputSub BETWEEN 1 AND 99 AND @Input > 1000) THEN 'And '
ELSE ''
END
+ CASE
WHEN (@Group = 1 AND @InputSub = 0 AND @Input >= 1.00) OR (@Group = 2 AND @InputSub = 0 AND @Input < 1.00) THEN ''
ELSE [dbo].[udf_CurrencyToWordsSub](@InputSub,@Group,@Currency)
END
SET @Counter = @Counter + 3
CONTINUE
END
--Fix plurals and return a plain Zero if required
SET @Output =
CASE
WHEN right(@CharInput,2) = '01' THEN replace(@Output,'~','')
ELSE replace(@Output,'~','s')
END
SET @Output =
CASE
WHEN @Input < 2 THEN replace(@Output,'#','')
ELSE replace(@Output,'#','s')
END
RETURN ltrim(rtrim(@Output))
END
Затем вы можете вызвать функцию, подобную этой
select dbo.[udf_CurrencyToWords] (8990.03,3)
result
Eight Thousand, Nine Hundred And Ninety Dollars And Three Cents
Просто измените @ валюту на нужную вам валюту
select dbo.[udf_CurrencyToWords] (8990.03,1)
Eight Thousand, Nine Hundred And Ninety Pounds And Three Pence