Author Topic: Align decimal points when printing  (Read 308 times)

eleusmario

  • Administrator
  • Newbie
  • *****
  • Posts: 19
    • View Profile
Align decimal points when printing
« on: May 31, 2018, 07:59:22 AM »
Variable Comb(5) String
Variable amt(5) Decimal
Variable result String
Var editMask String
Var x Integer, y Integer

Font Parent.Name = "Courier"

editMask = "0000.00"

Comb(0) = "Extra";                       amt(0) = 38.06
Comb(1) = "Visa";                        amt(1) = 124.62
Comb(2) = "Car Ins";                     amt(2) = 80.59

x = 0; y = 1
While x <= 2
  Position y, 1; Write Comb(x)
  result = Format(amt(x), editMask)
  result = RemoveZeros(result)
  Position y, 20; Write result
  x++; y++
Loop
EndProgram

Function RemoveZeros(S String) String
Var C Integer, T Integer, V String

T = StrPos(S, ".") - 2
C = 1
V = SubStr(S, C, 1)
While C <= T And V = "0"
  V = SubStr(S, C, 1)
  If V = "0"; RepStr S, " ", C, 1 ; EndIf
  C++
Loop
Return S
EndFunction

Daniel

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Align decimal points when printing
« Reply #1 on: June 26, 2018, 09:00:39 AM »
Did not work (version 1.0.49). However, it can be solved like this:

Code: [Select]
Variable Comb(5) String
Variable amt(5) Decimal
Variable result String
Var editMask String
Var x Integer, y Integer

Font Parent.Name = "Courier"

editMask = "######.00"

Comb(0) = "Extra";                       amt(0) = 28.06
Comb(1) = "Visa";                        amt(1) = 124.62
Comb(2) = "Car Ins";                     amt(2) = 80.59

x = 0; y = 1
While x <= 2
  Position y, 1; Write Comb(x)
  result = Format(amt(x), editMask) 
  result = RemoveZeros(result)
  Position y, 20; Write result
  x++; y++
Loop
EndProgram

Function RemoveZeros(S String) String
Var repeat Integer,
repeat = 10-StrLen(S)
S = SeqStr(repeat, " ") & S 
Return S
EndFunction