Hello. I’m working on a spreadsheet to help me at work. I have created a macro that scans a document and inserts a subtotal every time I leave a blank space in a list of parts. Everything is working as expected but I cannot find a way to make CStr give me an integer with 2 decimal places for the dollar. amount.
REM ***** BASIC *****
Sub caculate_subtotal()
oCtrl = ThisComponent.CurrentController
subTotal = 0
For i = 3 to 100
rem Scann Document for blank line
If oCtrl.ActiveSheet.GetCellRangeByName("E"+CStr(i)).Value = 0 Then
If subTotal > 0 Then
rem Print, then clear subtotal on blank line.
oCtrl.ActiveSheet.GetCellRangeByName("B"+CStr(i)).setString("Subtotal: $"+CStr(subTotal))
subTotal = 0
end If
else rem if line is not blank, add value to subtotal
subTotal = subTotal + oCtrl.ActiveSheet.GetCellRangeByName("E"+CStr(i)).Value
end If
next
End Sub
Currently if subTotal = 4.5 it prints
Subtotal: $4.5
I would like for it to print
Subtotal: $4.50