How to convert varchar to decimal(38,2)?

梦想的初衷 提交于 2021-02-11 17:15:32

问题


I have a problem converting from a varchar '000000113754' to decimal 1137.54

I'm comparing two expressions:

1. select STUFF('000000113754', LEN('000000113754') - 1, 0, '.')

2. select STUFF([dbo].fn_PrepareNumeric(('000000113754' + '-'), '+','-'), LEN('000000113754') - 1, 0, '.')

The function fn_PrepareNumeric just checks for the sign and appends '-' in front if the sign is -. That's all.

The problem is that the first expression gives me the correct varchar - 0000001137.54, and the second one does not: -000000113.754

Cannot figure out why?

来源:https://stackoverflow.com/questions/61085924/how-to-convert-varchar-to-decimal38-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!