'
' program name: Print_Using.bas
'
' This small program formats a float with two separate blocks.
' The first block is the interger part of the float separated
' in groups of three didits by a comma, the second group is
' the decimal part of the float rounded to 2 digits after the
' decimal point.
' The main purpose of this program is to format a float without
' using the PRINT USING command with a mask that places spaces
' in front of the mask when the float is smaller than the mask
' and that puts the % character when the float is larger than
' the mask.
' A better solution would be:
' 1) to modifiy the PRINT USING command in the way ANSI C or PHP
' printf() commands behave such as: printf("%.2f", float).
' 2) or to use the standard stdio.h library of the C ANSI to be
' able to use the printf() and sprintf() and other commands
' of the library.
'
' title of the windows when used in a console
'
'
' variable initialisation
'
Number# = 1.00
'
' main program
'
PRINT "Please enter a float: ";
PRINT "Using this function will print:" + Print_Using$
(Number#
) PRINT "PRINT USING command will print:";
'
' function to format the integer part of a float and round its decimal part at 2 digits.
'
Print_Using$ = intPart(nb#) + decPart(nb#)
'
' function to format and round the decimal part of a float at 2 digits.
'
dot$ = "."
partdec$ = ".00"
partdec$ = ".00"
partdec$ = partdec$ + "0"
partdec$
= LEFT$(partdec$
, 3) decPart$ = partdec$
'
' function to format the integer part of a float with groups of 3 digits.
'
idx = m3 + 4 + (m3 = 0)
i$
= LEFT$(i$
, idx
) + "," + MID$(i$
, idx
+ 1) idx = idx + 4
i$ = "0"
i$ = "-" + i$
intPart$ = i$