A question about formatting numbers

Hi Guys.

This isn’t so much a question as a “can someone explain this” sort of things

I am trying to subtract numbers in an interest column for a total interest number. Not big or fancy, but can someone explain why

newInterestPaidAfterLumpSumPayment = (newMortgageAmortizationProgramWindow.Label8.text.ToDouble) - (newMortgageAmortizationProgramWindow.ListBox1.CellTextAt(newMortgageAmortizationProgramWindow.ListBox1.RowCount-1,3).ToDouble)

will not work, if I format the number with something like ($$###,###.##).
If I remove it all works fine.

Just confused and curious…

Can you explain what ‘will not work’ means? Do you get an error?
If so, what type of error do you get?
What is the exact line of code that you use to format the number (maybe you are using a wrong format)?

I guess he is mixing presentation with processing. Need to be careful of correct decimal separator, and remove things like “$” from the string before conversion

Hi AlbertoD

With the formatting, it is as if the value is always 0.
I get negative numbers instead of a lower positive value, which I expected.

Thanks Rick and all.

If you expect format to output negative number you need a - on the start of your format. Otherwise the sign is ignored and a positive version is always output. If you add - before your string positives appear as they do, negatives are preceded with a - sign.

Don’t think that you know the format strings because you know Microsoft Excel, there are significant differences. Check the documentation.

Can you post the Xojo code you use to format?

Did you find the answer to this?

If you give us an example of what you have, what you want and what is what you get, we may help.

Hi Michael,

From what I see you are possibly using the format function with the wrong formatting characters. Please see my example which outputs the USD Currency formatting for your double number.
HTH,
Mike

// BREAK OUT FOR EASE OF IDE TROUBLESHOOTING 
Var label8ValueDbl as Double = newMortgageAmortizationProgramWindow.Label8.text.ToDouble
Var cellTextValDbl as Double = newMortgageAmortizationProgramWindow.ListBox1.CellTextAt(newMortgageAmortizationProgramWindow.ListBox1.RowCount-1,3).ToDouble

// PERFORM MATH
Var newInterestPaidAfterLumpSumPaymentDbl as Double = label8ValueDbl - cellTextValDbl

// FORMAT STRING
Var formattedLumpSumPayStr as String =  Format(newInterestPaidAfterLumpSumPaymentDbl, "\$###,###.00")