.. .. .. ..   ..
BlitzBasic > Codearchiv > MathematikAktuallisiert 30.05.2009

..  Punktierung von Zahlen - von rallimen/Triton 
Diese kleine Funktion ist nützlich, wenn man Zahlen für den User leserlicher gestalten will. Dazu wird nach jeweils 3 Stellen der Zahl ein Tausender-Trennpunkt eingefügt. Aus 100000 wird 100'000. Auch Brüche werden unterstützt - aus 1/12345 wird 1/12'345.


Global ttrenn$ = "'" ;Trennzeichen

Print "1234567 -> "+ pointing$("1234567")
Waitkey
End


;---
Function pointing$(zahl$)
;Grundfunction von rallimen, erweitert+verändert von Triton
;zahl element Q
l=Len(zahl$)
If Left$(zahl$,1)="-" Then 
	minus=1
	zahl$=Right$(zahl$,l-1)
	l=l-1
End If

bruchpos = Instr(zahl$,"/",2)
If bruchpos > 0 Then 
	zahla$=pointing$(Left$(zahl$, bruchpos-1))
	zahlb$=pointing(Mid$(zahl$,bruchpos+1))
	If minus = 1 Then Return "-"+zahla$+"/"+zahlb$
	If minus = 0 Then Return zahla$+"/"+zahlb$
End If

kommapos = Instr(zahl$,komma$,2)
If kommapos > 0 Then 
	zahlb$=zahl$
	zahl$=Left$(zahlb$,kommapos-1)
	zahlb$=Mid$(zahlb$,kommapos)
End If

While Len(zahl$) > 3 
	b$ = ttrenn$ + Right$(zahl$,3) + b$ 
	zahl$ = Left$(zahl$,Len(zahl$) - 3)
Wend
	
If minus=1 Then Return "-"+zahl$ + b$ + zahlb$
Return zahl$ + b$ + zahlb$ 

End Function