473,382 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Decimal problem

hey

ASP.NET 2.0

I'm created a webpage which displays money information. I mean it displays
amount of money like this:
23
32,6
456
1,5

The variable holding the amount is of DataType Double

As you see from the numbers above, some numbers have decimal and some
don't.. I would like to give all amount 2 digit decimals.. any suggestions
on how to do this?
Nov 7 '07 #1
2 980
Jeff wrote:
hey

ASP.NET 2.0

I'm created a webpage which displays money information. I mean it displays
amount of money like this:
23
32,6
456
1,5

The variable holding the amount is of DataType Double

As you see from the numbers above, some numbers have decimal and some
don't.. I would like to give all amount 2 digit decimals.. any suggestions
on how to do this?
Specify the format when you convert the value to a string:

amount.ToString("N2")

--
Göran Andersson
_____
http://www.guffa.com
Nov 7 '07 #2
RB
Göran Andersson wrote:
Jeff wrote:
>hey

ASP.NET 2.0

I'm created a webpage which displays money information. I mean it
displays amount of money like this:
23
32,6
456
1,5

The variable holding the amount is of DataType Double

As you see from the numbers above, some numbers have decimal and some
don't.. I would like to give all amount 2 digit decimals.. any
suggestions on how to do this?

Specify the format when you convert the value to a string:

amount.ToString("N2")
Alternatively use "C", as in String.Format ("{0:C}", myMoneyAmount)

This will display it as a currency, appropriate to your location.

See http://msdn2.microsoft.com/en-us/library/fht0f5be.aspx for info.

Cheers,

RB.
Nov 7 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
2
by: Steve Summit | last post by:
-----BEGIN PGP SIGNED MESSAGE----- It's often explained that the reason for some of the imprecision in C's definition is so that C can be implemented on different kinds of machines -- say, those...
11
by: Pieter | last post by:
Hi, I'm having some troubles with my numeric-types in my VB.NET 2005 application, together with a SQL Server 2000. - I first used Single in my application, and Decimal in my database. But a...
3
by: Daniel | last post by:
I'm writing an application that (among other things) evaluates mathematical expressions. The user enters strings containing literals and names that later get evaluated using the Python interpreter....
3
by: Mike Howarth | last post by:
Hi Seem to be having a bit of brainfreeze this evening. Basically I'm reducing an array of prices like so: This gives me a string of '86.00.00' which I am trying to use with decimal...
13
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post by:
Hi, Why does Math.Sqrt() only accept a double as a parameter? I would think it would be just as happy with a decimal (or int, or float, or ....). I can easily convert back and forth, but I am...
17
by: D'Arcy J.M. Cain | last post by:
I'm not sure I follow this logic. Can someone explain why float and integer can be compared with each other and decimal can be compared to integer but decimal can't be compared to float? True...
4
by: =?Utf-8?B?THVpZ2k=?= | last post by:
Hi all, I have an expression like this: decimal? ValoreComplessivoNettoDelfondoValue = (totaleAttivitaValue.HasValue || totalePassivitaValue.HasValue) ? ((totaleAttivitaValue ?? 0) -...
10
by: Jason | last post by:
I'm making a program that will convert decimal inputs (in this case, in inches) and output a fractional answer. At the moment, I'm only able to output the fractional answer in three parts: A whole...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.