Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6185373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:41:53+00:00 2026-05-24T01:41:53+00:00

For reasons I can not help I have a varchar column with data like

  • 0

For reasons I can not help I have a varchar column with data like the following: 820.0E-12, 10.0E+00.

I want the numeric value. So I have this test query which works:

declare @d varchar(256)
set @d = '820.0E-12'
select 
   CASE 
      WHEN @d like '%E-%' THEN LTRIM(RTRIM(CAST(CAST(@d AS FLOAT) AS DECIMAL(18,18))))
      WHEN @d like '%E+%' THEN NULL
      ELSE @d
   END

My result is: 0.000000000820000000 (which is what I want)

I change my SQL to account for the numbers > 0 (10.0E+00) like this:

WHEN @d like '%E+%' THEN CAST(@d AS FLOAT)

My result changes to: 8.2E-10 (which is NOT what I want)

If I change @d=’10.0E+00′ then I get 10 (which is correct).

I’ve got a view that I need to make the output from a varchar column, that contains scientific notation, casted/converted into decimal(18,18).

Can somebody tell me what craziness is going on here?

Or, maybe my question should be, how do I cast/convert a varchar scientific notation column to decimal output in a view?

My first WHEN statement works for numbers < 0 but I also need to account for numbers > 0. When I change the second WHEN, to include the CAST, it breaks/gives the wrong result.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:41:53+00:00Added an answer on May 24, 2026 at 1:41 am

    There’s a couple different problems all coming together here at the same time. Let’s look at some of them:

    1. You’re casting numbers as DECIMAL(18, 18). What that means is “give me a number that has room for a TOTAL of 18 characters, and 18 of them should be after the decimal”. That works fine as long as your number is smaller than 0 (which is true for all E- numbers) but it will break if you try to use it on numbers > 0. For numbers > 0, just cast as DECIMAL without specifying anything else.

    2. In the case where you add “WHEN @d like ‘%E+%’ THEN CAST(@d AS FLOAT)”, you’re getting different results for numbers < 0 because the engine is implicitly casting the result differently. I don’t know the rules on how sql server decides to cast CASE results, but apparently making your proposed change causes the engine to recast it in a different way. Explicitly casting those results as decimal fixes the issue.

    3. You need to LTRIM and RTRIM your results consistently. You can either add LTRIM and RTRIM to each case statement, or you can just LTRIM and RTRIM the results of the case.

    Here’s a solution that should totally solve everything:

    SELECT
        LTRIM(RTRIM(CASE 
            WHEN @d like '%E-%' THEN CAST(CAST(@d AS FLOAT) AS DECIMAL(18,18))
            WHEN @d like '%E+%' THEN CAST(CAST(@d AS FLOAT) AS DECIMAL)
            ELSE @d
        END))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Any reasons why this can not be standard behavior of free() ? multiple pointers
I can't seem to figure this one out. I have a validator-type script that
Can you please help me here, why the compiler does not infer the lambda
This is not a codefix question but please help me where possible. I am
I have a upload field where people can upload a image. I'd like to
I have a table like this (MySQL 5.0.x, MyISAM): response{id, title, status, ...} (status:
We're using ITextSharp for reasons I do not understand and we dont have the
I'm developing a data warehouse and have come up against a problem I'm not
Good day, I have this problem with Html.DropDownListFor which I can't seem to work
For some reason, I can not seem to change the default position of an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.