Solved

Print decimals in HTML

Posted on 2014-10-13
5
145 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 63

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 63

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 63

Expert Comment

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

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

617 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