We help IT Professionals succeed at work.

format a s currency ittem in a listview

Ernesto
Ernesto asked
on
hi all
how do i format as a currency

 lv.SubItems.Add(objRead("monto").ToString)

tsm
Comment
Watch Question

it_saigeDeveloper
Distinguished Expert 2019

Commented:
Use the C2 string format specifier; e.g.:
Public Class Form1
	Private objArray(5) As Object

	Private Sub OnLoad(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
		objArray(0) = 123.0
		objArray(1) = 57.34
		objArray(2) = 67
		objArray(3) = "NaN"
		objArray(4) = 58
		objArray(5) = 0.05

		Dim tempVal As Decimal
		For Each item In objArray
			lv.Items.Add(If(Decimal.TryParse(item, tempVal), tempVal.ToString("C2"), "Not a number"))
		Next
	End Sub
End Class

Open in new window

Produces the following output -Capture.JPG-saige-

Author

Commented:
lv.SubItems.Add(objRead("monto").ToString("C2", CultureInfo.CurrentCulture))

do not work
Developer
Distinguished Expert 2019
Commented:
In your case you will need to use something like:
lv.SubItems.Add(String.Format("{0:C2}", objRead("monto"))

Open in new window


-saige-

Author

Commented:
Man!!!!
tsm
your a %$#$%#$% Genious!!