Go Premium for a chance to win a PS4. Enter to Win

x
Solved

# Converting string to currency

Posted on 2016-09-20
Medium Priority
63 Views
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
``````
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
0
Question by:RIAS
• 5
• 4

LVL 22

Assisted Solution

p_davis earned 400 total points
ID: 41806700
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

Author Comment

ID: 41806722
Working great p_davis but, it puts Ā£ sign in front of the value.
Any suggestion ?
0

LVL 35

Accepted Solution

it_saige earned 1600 total points
ID: 41806812
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)
End Sub
End Module
``````
Produces the following output -
-saige-
0

LVL 22

Expert Comment

ID: 41806990
i think saige is correct in suggesting the use of N... sorry, of course, i assumed somethingn i shouldn't have.
0

Author Comment

ID: 41808515
Thanks Saige!!!
0

LVL 22

Expert Comment

ID: 41808573
doesn't anyone believe in splitting points anymore?
0

Author Comment

ID: 41808575
p_davis,
Sorry mate but,yours can be an assisted solution .Raising it.
0

LVL 22

Expert Comment

ID: 41808578
just appreciate a nod for the effort
0

Author Comment

ID: 41808582
P_davis,

Was operating the solution from phone.Just accepted the solution in hurry.
Thanks once again.
0

Author Closing Comment

ID: 41810204
Cheers!
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points withā¦
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. ā¦
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased riskā¦
###### Suggested Courses
Course of the Month9 days, 19 hours left to enroll