:SetVar Function "AUX:ToStringFS.DHP"
:r $(DropFunctionScript_AUX)
create function [$(Function)]( @Number $(dt_HPDecimal_AUX),
                               @AbsValueWidthForZeroPadding int = null )
returns $(dt_AnsiString_AUX)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# NUMBER CONVERSION TO STRING, WITH FIXED PRECISION (“$(dt_HPDecimal_AUX)” TYPE):
#
# === Usage: ===
# dbo.[AUX:ToStringFS.DHP]( <Number>, <Absolute value width for zero padding> )
# dbo.[AUX:ToStringFS.DHP]( <Number>, null )
#
==================================================================================================*/

if @Number is null return null

return dbo.[AUX:ZeroLeftPadByWidthOfAbs](
   CONVERT( $(dt_DecimalStr_AUX), @Number ),
   ISNULL( @AbsValueWidthForZeroPadding, $(num_DecimalStrMaxLength_AUX)-1 ) )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ToStringFS.DHP]( 345178.21354, 20 ) 'Number as string (fixed prec.)'
select dbo.[AUX:ToStringFS.DHP]( -8435, 20 ) 'Number as string (fixed prec.)'
*/
