Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Print decimals in HTML

Posted on 2014-10-13
5
Medium Priority
?
160 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
[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
  • 3
  • 2
5 Comments
 
LVL 64

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 64

Accepted Solution

by:
Fernando Soto earned 2000 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 64

Expert Comment

by:Fernando Soto
ID: 40377982
Not a problem RadhaKrishnaKiJaya, glad I was able to help.
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

This article discusses four methods for overlaying images in a container on a web page
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

670 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