Solved

Converting string to currency

Posted on 2016-09-20
10
52 Views
Last Modified: 2016-09-22
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
0
Comment
Question by:RIAS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 22

Assisted Solution

by:p_davis
p_davis earned 100 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

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

Accepted Solution

by:
it_saige earned 400 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)
		Console.ReadLine()
	End Sub
End Module

Open in new window

Produces the following output -Capture.JPG
-saige-
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 22

Expert Comment

by:p_davis
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

by:RIAS
ID: 41808515
Thanks Saige!!!
0
 
LVL 22

Expert Comment

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

Author Comment

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

Expert Comment

by:p_davis
ID: 41808578
just appreciate a nod for the effort
0
 

Author Comment

by:RIAS
ID: 41808582
P_davis,

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

Author Closing Comment

by:RIAS
ID: 41810204
Cheers!
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question