Bishoy Ezzat Bishoy Ezzat - 3 months ago 9
SQL Question

How to convert a numeric (15,2) to nvarchar(15)?

I want to convert a

numeric(15,2)
value to a
nvarchar(15)
string.

The value is
132.500m
, I want it the converted value to be
000000000013250
.

I wrote this code but it returns this
000000000000132
.

Code:

SELECT
REPLACE (STR(ROUND(CAST(MonthlyPayment.PaymentAmount AS NUMERIC(18,2)), 0, 1), 15), ' ', 0)
FROM
MonthlyPayment

Answer

Try it like this

DECLARE @d DECIMAL(15,2)=132.500;

SELECT REPLACE(STR(CAST(@d*100 AS int),15),' ','0')