Solved

Print decimals in HTML

Posted on 2014-10-13
5
134 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 Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
"The resource cannot be found" 1 24
Connect Gridview column to Textbox in C# 2 41
Hit counters in SharePoint 2013 2 30
asp.net, radiobuttonlist, c# 3 39
When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

730 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