Converting string to currency

Hello,
I am converting a datagridview value to currency

    If IsDBNull(sender.Rows(intRowIndex).Cells("Deposite").Value) = False Then
                str_Dep = CDbl(sender.Rows(intRowIndex).Cells("Deposite").Value)
            End If

Open in new window

but,the problem with the above code is that it converts
21.10 to 21.1 whereas the requirement is to convert it to 21.10
Any suggestions are welcome.

Cheers
RIASAsked:
Who is Participating?
 
it_saigeDeveloperCommented:
It puts the £ sign in front of the string because c is the currency specifier, if you do not want the £ sign in front then you should use N or G instead:
Module Module1
	Sub Main()
		Dim value As Decimal = 21.2

		Console.WriteLine("{1,15}{0,5}{2,15}{0,5}{3,15}", " ", "Currency", "General", "Numeric")
		Console.WriteLine("{1,15}{0,5}{1,15}{0,5}{1,15}", " ", New String("_", 15))
		Console.WriteLine("{1,15:C}{0,5}{1,15:G}{0,5}{1,15:N}", " ", value)
		Console.ReadLine()
	End Sub
End Module

Open in new window

Produces the following output -Capture.JPG
-saige-
0
 
p_davisCommented:
not sure if vb has the same string function this would be for c#
str_Dep = String.Format("{0:c}", CDbl(sender.Rows(intRowIndex).Cells("Deposite").Value))
0
 
RIASAuthor Commented:
Working great p_davis but, it puts £ sign in front of the value.
Any suggestion ?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
p_davisCommented:
i think saige is correct in suggesting the use of N... sorry, of course, i assumed somethingn i shouldn't have.
0
 
RIASAuthor Commented:
Thanks Saige!!!
0
 
p_davisCommented:
doesn't anyone believe in splitting points anymore?
0
 
RIASAuthor Commented:
p_davis,
Sorry mate but,yours can be an assisted solution .Raising it.
0
 
p_davisCommented:
just appreciate a nod for the effort
0
 
RIASAuthor Commented:
P_davis,

Was operating the solution from phone.Just accepted the solution in hurry.
Thanks once again.
0
 
RIASAuthor Commented:
Cheers!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.