Results 1 to 2 of 2

Thread: Conver format

  1. #1
    Join Date
    Oct 2002
    Location
    queens
    Posts
    139

    Conver format

    Can anyone help on the following situation...

    how to format a decimal lets say 5.40 into 000540?

    Thanks!!

  2. #2
    Join Date
    Dec 2004
    Posts
    502
    This sort of depends on how varied the numbers you are trying to convert are, but you can try this:

    DECLARE @decimal_number decimal(10, 2)
    SET @decimal_number = 5.40

    SELECT REPLICATE('0', 6 - LEN(REPLACE(CONVERT(varchar, @decimal_number), '.', ''))) + REPLACE(CONVERT(varchar, @decimal_number), '.', '')

    This code assumes that the length of your string is always going to be 6 characters long.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •