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 4580976
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:51:31+00:00 2026-05-21T20:51:31+00:00

I have a variable that I want to return a max of 5 to

  • 0

I have a variable that I want to return a max of 5 to the left of the decimal and always 3 to the right

CONVERT(VARCHAR(14),CONVERT(DECIMAL(8,3),
        DATEDIFF(MILLISECOND,@ProcessTime,GETDATE()))/@OneThousand)

Now variables are defined as

DECLARE @ProcessTime DATETIME 
DECLARE @OneThousand DECIMAL(8,3)
SET @OneThousand = 1000.000

This always returns something like

0.003000000000

I guess I can solve my problem with a left function, but my question is why does this happen at all. If the Minimum variable of decimal defined, @OneThousand, is 3 shouldn’t the return value have 3 decimals?

  • 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-21T20:51:32+00:00Added an answer on May 21, 2026 at 8:51 pm

    The result of the division of DECIMAL(8,3) by DECIMAL(8,3)gives a datatype of DECIMAL(20,12) to see this

    DECLARE @ProcessTime DATETIME =getdate()
    DECLARE @OneThousand DECIMAL(8,3)
    SET @OneThousand = 1000.000
    
    DECLARE @v SQL_VARIANT
    
    SET @v = CONVERT(DECIMAL(8,3),
            DATEDIFF(MILLISECOND,@ProcessTime,GETDATE()))/@OneThousand
    
    SELECT
        CAST(SQL_VARIANT_PROPERTY(@v, 'BaseType') AS VARCHAR(30)) AS BaseType,
        CAST(SQL_VARIANT_PROPERTY(@v, 'Precision') AS INT) AS Precision,
        CAST(SQL_VARIANT_PROPERTY(@v, 'Scale') AS INT) AS Scale
    

    The BOL section that explains why decimal(20,12) is here

    Operation:        e1 / e2
    Result precision: p1 - s1 + s2 + max(6, s1 + p2 + 1)
    Result scale:     max(6, s1 + p2 + 1)
    

    So in your case

    Result precision: 8 - 3 + 3 + max(6, 3 + 8 + 1) = 20
    Result scale:     max(6, 3 + 8 + 1)             = 12
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a member variable that in a class that I want to make
I have a certain session variable that is actually an array. I want to
i have a variable $cartTotal in cart.php page i want to use that same
i have value in php variable like that $var='2.500000550'; echo $var what i want
I have a variable known as $SessionMinus. What I want to do is that
I have a list of cities names that is variable and I want to
If I have a private variable that I want to have some internal validation
I want to have one variable that contains the root path to all my
I have a bunch of keys that each have an unlikeliness variable. I want
I have some user-submitted variables that I want to display in a different part

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.