Formatting as currency.

hlwc

New member
Joined
Dec 6, 2017
Messages
1
Programming Experience
1-3
Hey guys, had a quick question. -

Show the code needed to take the Double value stored in dblSample and display it formatted as currency in the Label lblResult.


I'm putting- lblResult.text = dblSample.ToString("c") , but every time I click the calculate button, it just gives me $0.00. Am I missing a line of code I need to put first, or is this just completely wrong in general? Any help would be appreciated, thanks!
 
The code you have is going to display the value of 'dblSmaple' in the standard system currency format in 'lblResult'. If you're seeing "$0.00" in that Label then that means that the formatting is working as it should. If you're expecting to see a number other than zero then you need to assign that number to 'dblSample' beforehand. If you're not assigning anything to that variable then it will contain its default value, which is zero.

Perhaps you're changing the value afterwards and expecting the Label to change. That's not going to happen. There is no live link between the Label and the Double value. If the Double value changes then you would need to execute that same code again to update the Label with the new value.
 
Back
Top