Thank you so much for posting here in Microsoft Q&A.
You will face 'Arithmetic overflow error converting float to data type numeric' error if you would like to convert one number whose precision of size is bigger than 30 to DECIMAL(30,4) like below example:
select Format(CAST(123456789123456789123456789123456.2541 AS DECIMAL(30,4)),'+00000000000000000000000000.0000;-00000000000000000000000000.0000')
In this case, you could firstly try to replace DECIMAL(30,4) with DECIMAL(38,4) as below since the maximum allowed size given to the type 'decimal' is (38).
select Format(CAST(1234567891234567891234564285378.2541 AS DECIMAL(38,4)),'+00000000000000000000000000.0000;-00000000000000000000000000.0000')
Output:
+1234567891234567891234564285378.2541
If above is not working, then you could have a try to replace cast with try_cast as below since try_cast returns null if a value is failed to cast to the specified data type.
select Format(TRY_CAST(1234567891234567891234564285378.2541 AS DECIMAL(30,4)),'+00000000000000000000000000.0000;-00000000000000000000000000.0000')
Output:
NULL
Best regards,
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.