MY-BASIC

string.format(<str::format>,<str::string>)

string.format(<str::format>,<int::integer>)

string.format(<str::format>,<dbl::number>)


Format a string, integer or floating value (second argument) according the format-control string (first argument).


Return value:         string


Arguments

format

str: Format control string with syntax:


       %[flags][width][.precision][length]specifier


specifier

Specifies the type of the output.

Most relevant specifiers are:

d or i

integer

f

floating point

e

scientific notation (mantissa/exponent), lowercase

E

scientific notation (mantissa/exponent), uppercase

g

shorter notation of e or f

G

shorter notation of E or F

s

string

 

length


width

Minimum number of characters to be printed; if the value to be printed is smaller, blank spaces are added.

precision

For f,e,E,g and G: number of digits to be printed after the decimal point

flags

-

Left-justify within the given field width

+

Result will be preceded by a - or + sign. By default, only negative numbers are preceded by a - sign

0

Left pads the number with zeroes instead of spaces

Note that the the # symbol does not work as this will be interpreted as the comment character during reading

string

str: Substring to find in string.


Examples

Print the total moles in the system, the phases (exchange, minerals, solid-solutions) and the aqueous phase of the primary components.

USER_PRINT

-mybasic

-start

  nmoles = sys("elements","count","names","types","moles")

  

  for i = 1 to count

    comp = names(i)

    if(string.find(comp,"(") < 0) then 

        write(string.format("%-5s",comp) + string.format("%-20s"," Total   (mole) ") + string.format("%18.12e",sys(comp)) + eol)

        write(string.format("%-5s",comp) + string.format("%-20s"," Aqueous (mole) ") + string.format("%18.12e",totmole(comp)) + eol)

        write(string.format("%-5s",comp) + string.format("%-20s"," Solid   (mole) ") + string.format("%18.12e",sys(comp)-totmole(comp)) + eol)

     endif

  next

-end


In a system with H, O, Ca, and Si, the user_print block in the output file is, for example,


----------------------------------User print-----------------------------------


H     Total   (mole)     5.852226105076e+01.

H     Aqueous (mole)     5.552766913095e+01

H     Solid   (mole)     2.994591919807e+00

O     Total   (mole)     3.100037832923e+01

O     Aqueous (mole)     2.777352864120e+01

O     Solid   (mole)     3.226849688032e+00

Ca    Total   (mole)     1.119218076064e+00

Ca    Aqueous (mole)     9.662913359766e-03

Ca    Solid   (mole)     1.109555162705e+00

Si    Total   (mole)     3.100148638994e-01

Si    Aqueous (mole)     1.558118753008e-05

Si    Solid   (mole)     3.099992827118e-01