Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:scriptsamples:paddigits [2015/09/14] (current)
Line 1: Line 1:
 +====== Padding numbers with leading zeros ======
 +> **Developer:​** //​[[developer:​rhinoscript|RhinoScript]]//​
 +> **Summary:​** //​Demonstrate how to pad numbers with leading zeros.//
 +
 +===== Question =====
 +How do I pad digits with leading zeros? For example, if I have the number 24, how can I print it as "​0024"?​
 +
 +===== Answer =====
 +The following utility function will pad an integer with a specified number of digits.
 +
 +<code vb>
 +Function PadDigits(val,​ digits)
 +  PadDigits = Right(String(digits,"​0"​) & val, digits) ​
 +End Function ​
 +</​code>​
 +
 +You can use this function as such:
 +
 +<code vb>
 +For i = 0 To 25
 +  Rhino.Print PadDigits(i,​ 4)
 +Next
 +</​code>​
 +
 +The output, printed to the command, will be:
 +
 +<​code>​
 +0000
 +0001
 +0002
 +0003
 +0004
 +0005
 +0006
 +0007
 +0008
 +0009
 +0010
 +...
 +</​code>​
 +
 +\\
 +
 +{{tag>​Developer RhinoScript}}
  
developer/scriptsamples/paddigits.txt ยท Last modified: 2015/09/14 (external edit)