Skip to content

string_format

CryoEagle edited this page Dec 26, 2018 · 6 revisions

string_format

Turns a real number into a string using your own formatting.

Syntax:

string_format(val, tot, dec)
Argument Description
int val The real number to be turned into a string.
int tot The total number of places of the main number to be shown. Zeroes or spaces will be inserted to match this.
int dec The number of decimal places to be included.

Returns: string

Description

Turns a real number into a string using your own formatting, where you can choose how many "places" are saved to the string and how many decimal places are saved also. Both can be very handy, some games prefer to display a score as a set number of digits, while control over decimal places can be good for a high accuracy the two decimal places of string() cannot provide. If the number of places specified is greater than the value to be shown and/or the number plus the decimal places that have been specified is less than the total places, then spaces will be added before the value to make up the difference (see the example below). Zeros will be added to the right of the decimal point if the value given is less than the total and the number of decimal places to include.

Example:

str1 = string_format(1234, 8, 0);
str2 = string_format(pi, 1, 10);
str3 = string_format(pi, 5, 5);

This will set str1 to " 1234", str2 to "3.1415926535" and str3 to " 3.14159".

Back to strings

Clone this wiki locally