Solved

Print decimals in HTML

Posted on 2014-10-13
5
118 Views
Last Modified: 2014-10-13
Hello Experts,
I am printing a HTML Payment Receipt in C# class file.  The problem is 1.00 is printed as $1, 1:09 is printer as 1.09, 1.10 is printed as 1.1.  I requirement is it should print 2 decimals, no matter what.  For example 1 should print 1.00.  Any idea?  Please try to help.

Thank you very much in advance for your time and help.
0
Comment
Question by:RadhaKrishnaKiJaya
  • 3
  • 2
5 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40377766
Hi  RadhaKrishnaKiJaya;

Use the ToString("C") method on the numeric value to format the value in to a string format with a leading $ and always with two decimal position at the end.
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 40377793
Actually use "C2" on the ToString to make sure it always has two digits after the decimal point.

Examples

// val will contain the string $1.10
string val = (1.10).ToString("C2");
decimal dec = 1.09M;
// val2 will contain the string $1.09
string val2 = dec.ToString("C2");

Open in new window

0
 

Author Comment

by:RadhaKrishnaKiJaya
ID: 40377937
Yup. You are right.  Thank you very much for your help.
0
 

Author Closing Comment

by:RadhaKrishnaKiJaya
ID: 40377943
Comments already posted.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40377982
Not a problem RadhaKrishnaKiJaya, glad I was able to help.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now