Built-in Functions
Structures
Built-in Variables and Constants
Conventions
Exchanges
File.printf
Write formatted data to file.
printf(format)
printf(format, arg1, arg2, ...argN)Examples
Write formatted trading data.
javascript
function main() {
let file = os.open("trade_log.txt", "w+")
let price = 100.25
let volume = 1000
let bytes = file.printf("Price: %.2f, Volume: %d\n", price, volume)
Log("Formatted bytes written:", bytes)
file.seek(0, 0)
let data = file.read()
Log("data:", data)
// Output: data: Price: 100.25, Volume: 1000
// file.printf("| Price: %.2f, Volume: %d\n") // "| Price: %!f(MISSING), Volume: %!d(MISSING)"
// file.seek(0, 0)
// data = file.read()
// Log("data:", data)
file.close()
}Returns
| Type | Description |
number | Returns the actual number of bytes written. |
Arguments
| Name | Type | Required | Description |
format | string | Yes | Format string. |
args | any | No | Format arguments. |
See Also
Remarks
Supported verbs: %s, %d, %f, %v and %%, with flags (-, 0), width and precision, e.g. %.2f, %-8s, %08d. A missing argument is written as placeholder text such as %!d(MISSING).