SQL Server:将varchar转换为十进制(还要考虑指数表示法) [英] SQL Server: Convert varchar to decimal (with considering exponential notation as well)

查看:95
本文介绍了SQL Server:将varchar转换为十进制(还要考虑指数表示法)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要转换表的数据并进行一些操作。

I need to convert data of a table and do some manipulation.

列数据类型之一是 Varchar ,但存储十进制数字。
我正在努力将 varchar 转换为十进制

One of the column datatypes is Varchar, but it stores decimal numbers. I am struggling to convert the varchar into decimal.

我尝试了 CAST(@ TempPercent1 AS DEMAL(28,16))

问题是该数据还具有一些指数表示形式的值,例如: 1.61022e-016

Problem is that data also has some values in exponential notation, for example: 1.61022e-016.

sql查询是在遇到这样的值时抛出错误。
错误是将数据类型varchar转换为数字错误。

The sql query is throwing error on encountering such value. The error is Error converting data type varchar to numeric.

我应该如何处理指数表示法值

How should I handle exponential notation values during varchar to decimal conversion?

推荐答案

您可以尝试执行以下操作,但可能会降低准确性:

You may try following, but you may loose accuracy:

select cast(cast('1.61022e-016' AS float) as DECIMAL(28, 16))

这篇关于SQL Server:将varchar转换为十进制(还要考虑指数表示法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆