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
Solved

Print decimals in HTML

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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 the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

789 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