?
Solved

Easy question

Posted on 2010-01-07
8
Medium Priority
?
254 Views
Last Modified: 2013-12-17
double d1 = 8501.23
double d2 = -199

I want it to format using String.Format to ouput as
8,501.13
(199)

Thanks
0
Comment
Question by:Ashok
8 Comments
 
LVL 13

Expert Comment

by:zadeveloper
ID: 26202285
decimal.Round(100.54, 0)
0
 
LVL 61

Accepted Solution

by:
HainKurt earned 600 total points
ID: 26202323
try this...

function myFormatNumber(n as decimal) return string
  if n>0 then
    return ...
  else
    return "(" & -n & ")"
  end if
end function
0
 
LVL 13

Author Comment

by:Ashok
ID: 26202388
double d1 = 8501
double d2 = -199

I want it to format using String.Format to ouput as
8,501
(199)

Thanks
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 400 total points
ID: 26202512
Per http://www.csharp-examples.net/string-format-double/
// Format
String.Format("{0:0,0.00;(0,0.00);zero}", 123.4567);

// Example using your data
String.Format("{0:0,0.00;(0,0.00);zero}", d1)
String.Format("{0:0,0.00;(0,0.00);zero}", d2)

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 26202519
You can remove the ".00" part of the format specifier if you do not want the decimal values to be shown.
0
 
LVL 13

Author Comment

by:Ashok
ID: 26202602
HainKurt,

Your solution worked.
But I also found following to be working.....
if (Convert.ToDouble(value) < 0)
  return String.Format("{0:(#,###)}", Convert.ToDouble(value) * -1);
else
  return String.Format("{0:#,###}", value);

Thanks
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 26202649
Wow. Give the ppl what they ask for...    and the ppl give you an assist...  
0
 
LVL 13

Author Comment

by:Ashok
ID: 26205814
kaufmed,

Sorry, I did not test your solution which does not require use of checking negative numbers.
As a bonus: I will post similar question with different requirements so if you answer it correctly, I will give you all points.

Thanks,
Ashok
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
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

840 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