Internal functions/Conversion functions
From Avisynth wiki
(Difference between revisions)
m (1 revision) |
|||
Line 22: | Line 22: | ||
: If the variable is float or integer, it first converts it to a float and then uses format_string to convert the float to a string. The syntax of format_string is as follows: | : If the variable is float or integer, it first converts it to a float and then uses format_string to convert the float to a string. The syntax of format_string is as follows: | ||
: <tt>%[flags][width][.precision]f</tt> | : <tt>%[flags][width][.precision]f</tt> | ||
− | |||
− | |||
: ''flags'': | : ''flags'': | ||
:: <tt>- </tt> left align (instead right align) | :: <tt>- </tt> left align (instead right align) | ||
Line 30: | Line 28: | ||
:: <tt>' '</tt> print a blank instead of a "+" | :: <tt>' '</tt> print a blank instead of a "+" | ||
:: <tt># </tt> always print the decimal point | :: <tt># </tt> always print the decimal point | ||
+ | : ''width'': the minimum width (the string is never truncated) | ||
+ | : ''precision'': the number of digits printed | ||
: You can also put arbitrary text around the format_string as defined above, similar to the C-language ''printf'' function. | : You can also put arbitrary text around the format_string as defined above, similar to the C-language ''printf'' function. | ||
: ''Examples:'' | : ''Examples:'' | ||
Line 36: | Line 36: | ||
[[Subtitle]]( "Value of x is " + String(x, "%.3f") + " after AR calc") ) # same as above | [[Subtitle]]( "Value of x is " + String(x, "%.3f") + " after AR calc") ) # same as above | ||
String(1.23, "%f") = '1.23' | String(1.23, "%f") = '1.23' | ||
− | String(1.23, "%5.1f") = ' 1.2' | + | String(1.23, "%5.1f") = ' 1.2' |
String(1.23, "%1.3f") = '1.230' | String(1.23, "%1.3f") = '1.230' | ||
String(24, "%05.0f") = '00024' | String(24, "%05.0f") = '00024' |
Revision as of 19:03, 30 June 2013
Conversion functions
These functions convert between different types. There are also some numeric functions that can be classified in this category, namely: Ceil, Floor, Float, Int and Round.
- Value | v2.07 | Value(string)
- Converts a decimal string to its associated numeric value.
- Examples:
Value ("-2.7") = -2.7
- HexValue | v2.07 | HexValue(string)
- Converts a hexadecimal string to its associated numeric value.
- Examples:
HexValue ("FF00") = 65280
- Hex | v2.60 | Hex(int)
- Converts a numerical value to its hexadecimal value. See Colors for more information on specifying colors.
- Examples:
Hex (10824234) = "A52A2A"
- String | v2.07 | String(float / int [, string format_string])
- Converts a variable to a string.
- If the variable is float or integer, it first converts it to a float and then uses format_string to convert the float to a string. The syntax of format_string is as follows:
- %[flags][width][.precision]f
- flags:
- - left align (instead right align)
- + always print the +/- sign
- 0 padding with leading zeros
- ' ' print a blank instead of a "+"
- # always print the decimal point
- width: the minimum width (the string is never truncated)
- precision: the number of digits printed
- You can also put arbitrary text around the format_string as defined above, similar to the C-language printf function.
- Examples:
Subtitle( "Clip height is " + String(last.height) ) Subtitle( String(x, "Value of x is %.3f after AR calc") ) Subtitle( "Value of x is " + String(x, "%.3f") + " after AR calc") ) # same as above String(1.23, "%f") = '1.23' String(1.23, "%5.1f") = ' 1.2' String(1.23, "%1.3f") = '1.230' String(24, "%05.0f") = '00024'
Back to Internal functions.