FICO
FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserPrevious exampleNext example

Output formatting

Description
The printing format for real numbers may be changed individually with the functions strfmt, textfmt, formattext or by resetting the parameter REALFMT. The function strfmt may also be applied to strings, for instance to change the alignment of the text.

Further explanation of this example: 'Mosel User Guide', Sections 10.1 Producing formatted output and 10.3 Real number format


Source Files
By clicking on a file name, a preview is opened at the bottom of this page.
fo.mos[download]
numformat.mos[download]
transport2.mos[download]
transport2t.mos[download]

Data Files





numformat.mos

(!******************************************************
   Mosel User Guide Example Problems
   ================================= 

   file numformat.mos 
   `````````````````` 
   Formatted output printing.
 
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, 2005, rev. Mar 2022
*******************************************************!)

model "Formatting numbers"
 parameters
  a = 123456789000.0
  b = 123456789008.9
  c = 12.0000000045
  d = 12.0
 end-parameters

 setparam("TXTZTOL", false)      ! Disable use of 'zerotol' for display

 writeln("Default:", a, "  ", b, "  ", c, "  ", d)
 
 setparam("REALFMT", "%1.2f")
 writeln("%1.2f:  ", a, "  ", b, "  ", c, "  ", d)

! Exact (conservative) representation of floating point numbers
 setparam("REALFMT", "%.17g")
 writeln("%.17g:  ", a, "  ", b, "  ", c, "  ", d)

 setparam("REALFMT", "%y")
 writeln("%y:     ", a, "  ", b, "  ", c, "  ", d)

 setparam("REALFMT", "%j")
 writeln("%j:     ", a, "  ", b, "  ", c, "  ", d)
end-model

Back to examples browserPrevious exampleNext example