Getting Started with Adobe After Effects - Part 6: Motion Blur
A collection of quick technology learning tips from what people around you learn every day

Convert Floats to Strings of Equal Length

Jul 27 2012 12:00AM by a.diniz   

Typically when we require a number to be represented as a string we employ a CAST or CONVERT. Sometimes though we want to preserve the natural 'sortability' of the numbers after the conversion and this poses a problem as string '8' is "bigger" than string '10' when evaluated for sorting. Here's a little trick I just learned to tackle this:

SELECT STR(num, length)

This casts num to a varchar of length characters. If num has fewer digits than length, it is padded with the appropriate number of leading spaces. So in our example, STR(8, 2) yields the string ' 8' which is "smaller" than '10' so the natural sortability of the 'stringified' number is preserved.

Read More..   [32134 clicks]

Published under: General Technology Tips ·  ·  ·  · 


a.diniz
310 · 0% · 137
8
 
3
 
 
0
Incorrect
 
0
Interesting
 
0
Forgotten



Submit

1  Comments  

  • CONVERT(VARCHAR, DateColumn, 111)

    Will do the same for a date column.

    commented on Jul 29 2012 5:35PM
    Dave Vroman
    132 · 1% · 375

Your Comment


Sign Up or Login to post a comment.

"Convert Floats to Strings of Equal Length" rated 5 out of 5 by 8 readers
Convert Floats to Strings of Equal Length , 5.0 out of 5 based on 8 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]