Code archives/Miscellaneous/Format a number

This code has been declared by its author to be Public Domain code.

Download source code

Format a number by skn32003
Allows you to format a number and return it in a string.
Print Format$("345233","#,###.##")
WaitKey()
Function Format$(Number,FormatString$)
	MakeFormat$=""
	NumberCount=1
	For I=1 To Len(FormatString$)
		GetFormatChar$=Mid$(FormatString$,I,1)
		Select GetFormatChar$
			Case ","
				MakeFormat$=MakeFormat$+","
			Case "."
				MakeFormat$=MakeFormat$+"."
			Case "#"
				If NumberCount > Len(Number) Then
					GetNumberChar$="0"
				Else
					GetNumberChar$=Mid$(Number,NumberCount,1)
				End If
				NumberCount=NumberCount+1
				MakeFormat$=MakeFormat$+GetNumberChar$
		End Select
	Next
	Return MakeFormat$
End Function

Comments

Mikorians2014
This didn't work when I fed it a float value.
Tried fixing Number refs to Number$, still no good.


Code Archives Forum