Convert decimal to percentage and percentage to decimal

  • How to convert these value from VARCHAR to decimal  and remove percentage sign.
    DECLARE @b-2 VARCHAR(100) = '100.59%'
    DECLARE @b-2 VARCHAR(100) = '38.90%'

  • SELECT CONVERT(decimal(8,4),REPLACE(@B, '%','')) / 100;
    --Or, if you want ANSI SQL
    SELECT CAST(REPLACE(@B, '%','') AS decimal(8,4)) / 100;

    Edit: Best practice, store your Percentage values as decimals, and then have your presentation layer worry about the formatting (hopefully this is the intention behind your question, 🙂 )

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply