locked
How to show fractional numbers in Report RRS feed

  • Question

  • Hi

    I create a new report for prescription .the doctor enter 0.5 tablet i need to show 1/2 in  prescription.so that patients can easily understand.Is it possible in SSRS ?  or shall i use resource library project. please suggest me. i need to show to doctor.


    Thanks & Regards Manoj

    Monday, January 28, 2013 2:44 AM

Answers

  • Thanks for the question. It was an interesting challenge. I have a solution using TSQL:

    DECLARE @Results AS TABLE(
    	Numerator INT,
    	Denominator INT)
    DECLARE @X FLOAT
     ,@S VARCHAR(20)
     ,@R VARCHAR(20)
     ,@Places INT
     ,@N INT
     ,@D INT
     ,@NB BIT
     ,@DB BIT
     ,@COUNTER INT
    
    SET @X = 0.6250
    SET @S = CAST(@X AS VARCHAR(20))
    SET @R = REVERSE(SUBSTRING(@S, CHARINDEX('.', @S) + 1, 20))
    
    SELECT @Places = LEN(SUBSTRING(@R, PATINDEX('%[1-9]%', @R), 20))
    
    SET @N=@X*POWER(10,@Places)
    SET @D=1*POWER(10,@Places)
    
    
    SET @COUNTER = @D
    
    WHILE @COUNTER > 0
    BEGIN
     SET @NB = @N % @Counter 
     SET @DB = @D % @Counter 
     IF @NB=0 AND @DB=0
     BEGIN
      INSERT INTO @Results VALUES (@N/@COUNTER, @D/@COUNTER)
      BREAK
     END
     SET @Counter = @Counter - 1
    END
    
    SELECT * FROM @Results

    Where I have SET @X = 0.6250, substitute your decimal value for the .6250 (the formula ignores trailing zeros). This is accurate to 6 decimal places (You can increase the number of decimal places but it takes quite a while to determine the values for Numerator and Denominator). It returns a Numerator and Denominator field for your fraction that you can then display in your report as a fraction by entering an expression in the TextBox:

    =CStr(Fields!Numerator.Value)+"/"+CStr(Fields!Denominator.Value)

    Let me know if this will work for you.


    Please Mark posts as answers or helpful so that others can more easily find the answers they seek.


    • Edited by Tim Pacl Monday, January 28, 2013 9:28 PM
    • Proposed as answer by Charlie Liao Tuesday, January 29, 2013 2:35 AM
    • Marked as answer by Charlie Liao Friday, February 1, 2013 10:01 AM
    Monday, January 28, 2013 9:22 PM