:SetVar Function "AUX:FormatByWidth.DecMoney"
:r $(DropFunctionScript_AUX)
GO
create function [$(Function)]( @Number $(dt_DecMoney_AUX),
                               @WidthForPadding int = null,
                               @ExpressiveDisplayNull bit = 0 )
returns $(dt_AnsiString_AUX)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# NUMBER FORMATTING BY WIDTH (“$(dt_DecMoney_AUX)” TYPE):
# - LEFT COMPLEMENT WITH SPACES;
# - DENOTION OUT OF SPACE CHARACTERS AS “*”;
# - POSSIBLE DISPLAYING NULL-S AS REPLICATION OF “-” CHAR
#
# === Usage: ===
# dbo.[AUX:FormatByWidth.DecMoney]( <Number>, <Width for padding>, <Display null expressively> )
# dbo.[AUX:FormatByWidth.DecMoney]( <Number>, <Width for padding>, 0 )
# dbo.[AUX:FormatByWidth.DecMoney]( <Number>, <Width for padding>, 1 )
# dbo.[AUX:FormatByWidth.DecMoney]( <Number>, <Width for padding>, default )
# dbo.[AUX:FormatByWidth.DecMoney]( <Number>, null, 0 )
# dbo.[AUX:FormatByWidth.DecMoney]( <Number>, null, 1 )
# dbo.[AUX:FormatByWidth.DecMoney]( <Number>, null, default )
#
==================================================================================================*/

return dbo.[AUX:FormatNumByWidth]( dbo.[AUX:ToString.DecMoney]( @Number ),
   ISNULL( @WidthForPadding, $(num_MoneyStrMaxLength_AUX) ),
   @ExpressiveDisplayNull )

/*================================================================================================*/
END
GO
/*
select '“'+dbo.[AUX:FormatByWidth.DecMoney]( 345178.21354, 7, 0 )+'”' 'Money as string by width'
select '“'+dbo.[AUX:FormatByWidth.DecMoney]( -8435, 3, 0 )+'”' 'Money as string by width'
select '“'+dbo.[AUX:FormatByWidth.DecMoney]( 345178.21354, null, 0 )+'”' 'Money as string by width'
select '“'+dbo.[AUX:FormatByWidth.DecMoney]( null, 5, 0 )+'”' 'Money as string by width'
select '“'+dbo.[AUX:FormatByWidth.DecMoney]( null, 5, 1 )+'”' 'Money as string by width'
select '“'+dbo.[AUX:FormatByWidth.DecMoney]( null, 5, default )+'”' 'Money as string by width'
*/
