Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 13th, 2005, 03:09 AM
Authorized User
 
Join Date: Oct 2005
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to richie86
Default Help with String Format(ASP.NET C#)

1. how we display the text with format the decimal place of a float or double number?
For example:
3.8456 will result in 3.85 (if we limit the decimal place to 2)

2. how we extract the character from a string?
This is same like the mid(), left(), or right() in Visual Basic.
But in c# we have to use string format? and what is the format string that we should use?

Any help would appreciate.


Goh Hoang Yuh
- C# Beginner in ASP.NET
 
Old November 14th, 2005, 02:20 PM
Authorized User
 
Join Date: Jul 2005
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

1.) double beforeRound = 3.8456;
     double afterRound = System.Math.Round(beforeRound ,2)

2.) I use SubString



 
Old November 15th, 2005, 05:57 AM
Authorized User
 
Join Date: Oct 2005
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to richie86
Default

oh i see. hmm thanks anyway ya.

Goh Hoang Yuh
- C# Beginner in ASP.NET
 
Old September 20th, 2007, 07:43 PM
Registered User
 
Join Date: Sep 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I recommend to use static method String.Format() instead of rounding the number. Use:
Code:
Console.WriteLine(String.Format("formatted number = {0:0.00}", 3.8456));
The output is: "formatted number = 3.85"

See this article for more information how to format float numbers using String.Format in C#.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert Rich Text Format to Ordinary Format in ASP Andraw Classic ASP Basics 1 August 31st, 2007 10:05 AM
Reg: displaying datase in xml format asp.net 2.0 sadiashoiab ADO.NET 0 April 19th, 2007 03:17 PM
(VB.net): Input string was not in a correct format sandeepyadav VB.NET 2002/2003 Basics 1 November 10th, 2006 11:18 AM
URGENT-How To Format Datagrid in ASP.NET? sarunmphil ADO.NET 2 January 21st, 2005 07:58 AM
Setting date format from ASP.NET jonashilmersson Crystal Reports 0 November 14th, 2003 04:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.