473,698 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

string number format

when I use the snippet below

price = "$" + reader["start_pric e"].ToString() + " to $" +
reader["end_price"].ToString();

the price is returned with 4 decimal places

I thought I could do; reader["start_pric e"].ToString("C") to format the
string as currency and do away "$" + from the line

or reader["start_pric e"].ToString("00.0 0") to at least specify the decimal
places

but niether work

What am I doing wrong

Regards

Wayne
Nov 15 '05 #1
8 7135
I also tried
price = "$" + Convert.ToDecim al( reader["start_pric e"]).ToString("0.0 0") + "
to $" + Convert.ToDecim al( reader["end_price"]).ToString("C") ;

I tried tostring("C2") as well

which compiled at least but did not make any difference to the output ie
still four decimal places

"LW Irving" <li*****@coffs. com.au> wrote in message
news:ue******** ******@TK2MSFTN GP12.phx.gbl...
when I use the snippet below

price = "$" + reader["start_pric e"].ToString() + " to $" +
reader["end_price"].ToString();

the price is returned with 4 decimal places

I thought I could do; reader["start_pric e"].ToString("C") to format the
string as currency and do away "$" + from the line

or reader["start_pric e"].ToString("00.0 0") to at least specify the decimal
places

but niether work

What am I doing wrong

Regards

Wayne

Nov 15 '05 #2
When you try
price = Convert.ToDecim al( reader["end_price"]).ToString("C") ;

what do you get as price?

José

"LW Irving" <li*****@coffs. com.au> a écrit dans le message de
news:u5******** ******@TK2MSFTN GP10.phx.gbl...
I also tried
price = "$" + Convert.ToDecim al( reader["start_pric e"]).ToString("0.0 0") + " to $" + Convert.ToDecim al( reader["end_price"]).ToString("C") ;

I tried tostring("C2") as well

which compiled at least but did not make any difference to the output ie
still four decimal places

"LW Irving" <li*****@coffs. com.au> wrote in message
news:ue******** ******@TK2MSFTN GP12.phx.gbl...
when I use the snippet below

price = "$" + reader["start_pric e"].ToString() + " to $" +
reader["end_price"].ToString();

the price is returned with 4 decimal places

I thought I could do; reader["start_pric e"].ToString("C") to format the string as currency and do away "$" + from the line

or reader["start_pric e"].ToString("00.0 0") to at least specify the decimal places

but niether work

What am I doing wrong

Regards

Wayne


Nov 15 '05 #3
Please,can you tell me,witch function converts integer to
string?
Thank you
Nov 15 '05 #4
LW Irving <li*****@coffs. com.au> wrote:
when I use the snippet below

price = "$" + reader["start_pric e"].ToString() + " to $" +
reader["end_price"].ToString();

the price is returned with 4 decimal places

I thought I could do; reader["start_pric e"].ToString("C") to format the
string as currency and do away "$" + from the line

or reader["start_pric e"].ToString("00.0 0") to at least specify the decimal
places

but niether work

What am I doing wrong


Firstly, we need to know what reader["start_pric e"] is returning. Then
we need to know what you mean by "but neither work" - in what *way*
don't they work?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #5
djozy <an*******@disc ussions.microso ft.com> wrote:
Please,can you tell me,witch function converts integer to
string?


Convert.ToStrin g, or Int32.ToString, or String.Format would all be good
starting points.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #6
As far as I know (Convert.ToDeci mal(Value)).ToS tring("0.00") should work
because it come from the IFormatter interface and is the same one used for
Float's. Double's etc...

I have used this many times... oh and there is just one thing you shoudl
undestand about the IFormatter if you do the following
(Convert.ToDeci mal(Value)).ToS tring("0.00") it will round up to the nearest
2 it doesnt just chop off the rest... which is cool

Mitch

"LW Irving" <li*****@coffs. com.au> wrote in message
news:ue******** ******@TK2MSFTN GP12.phx.gbl...
when I use the snippet below

price = "$" + reader["start_pric e"].ToString() + " to $" +
reader["end_price"].ToString();

the price is returned with 4 decimal places

I thought I could do; reader["start_pric e"].ToString("C") to format the
string as currency and do away "$" + from the line

or reader["start_pric e"].ToString("00.0 0") to at least specify the decimal
places

but niether work

What am I doing wrong

Regards

Wayne

Nov 15 '05 #7
Thanks for the replies
I was mistaken (ie. I was altering a method that was not being called
therefore there was no observable change)
The start_price variable is a sql variable in the data base it is decared as
smallmoney, it seems to behave as if double.

These two statements work
price = "$" + Convert.ToDecim al(reader["start_pric e"]).ToString("0.0 0")
or
price = Convert.ToDecim al(reader["start_pric e"]).ToString("C",
NumberFormatInf o.CurrentInfo)
With the second I do not need to put in the dollar sign

I need to do this about 120 - 130 times to fix the code ( I did not write it
originally and am just learning c# as I go)

these methods are on pages a in a folder called modules on pages called
along the lines of S3generalDB.cs

So my next question is can I do something like

price = myprice

and have a method that says

myprice = Convert.ToDecim al(reader["start_pric e"]).ToString("C",
NumberFormatInf o.CurrentInfo)

if should I put it at the top of the page , and how should I declare it

Sorry if this is too simple but I am really new to .net and C#

Regards

Wayne



"LW Irving" <li*****@coffs. com.au> wrote in message
news:ue******** ******@TK2MSFTN GP12.phx.gbl...
when I use the snippet below

price = "$" + reader["start_pric e"].ToString() + " to $" +
reader["end_price"].ToString();

the price is returned with 4 decimal places

I thought I could do; reader["start_pric e"].ToString("C") to format the
string as currency and do away "$" + from the line

or reader["start_pric e"].ToString("00.0 0") to at least specify the decimal
places

but niether work

What am I doing wrong

Regards

Wayne

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.543 / Virus Database: 337 - Release Date: 11/21/2003
Nov 15 '05 #8
Well because C# is Component/Object Orientated (Where as C is Procedural
i.e. declare first then use etc...)
Yes Something like this:
decimal myprice = 0.0M;
decimal price = myprice;

myprice = Convert.ToDecim al(reader["start_pric e"]).ToString("C",
NumberFormatInf o.CurrentInfo);

: will work becuase C# doesnt look at the lines and say erf oops here is
something wrong, to get a better grasp of how C#/.NET works I recommend
familiarise yourself with MSIL the underlying stuff that makes .NET,.NET...
for instance if you look at the code above in MSIL (compile the view exe or
dll in ILDASM) you will notice that you are doing quite a bit of boxing and
unboxing. (Casting from Reference Type to Value Type and Vice Versa) Try
this.... SQL types are said to be more accurate...

decimal myprice = 0.0M;

string price = myprice.ToStrin g("C", NumberFormatInf o.CurrentInfo)
// If you call price here now you will get $0.00
myprice = (decimal)myRead er.GetSqlMoney( 0);
// but if you call it here (lets say the DB returns 10.0000) you will get
$10.00 does this clear things up ??

Mitch

"LW Irving" <li*****@coffs. com.au> wrote in message
news:u5******** *****@TK2MSFTNG P11.phx.gbl...
Thanks for the replies
I was mistaken (ie. I was altering a method that was not being called
therefore there was no observable change)
The start_price variable is a sql variable in the data base it is decared as smallmoney, it seems to behave as if double.

These two statements work
price = "$" + Convert.ToDecim al(reader["start_pric e"]).ToString("0.0 0")
or
price = Convert.ToDecim al(reader["start_pric e"]).ToString("C",
NumberFormatInf o.CurrentInfo)
With the second I do not need to put in the dollar sign

I need to do this about 120 - 130 times to fix the code ( I did not write it originally and am just learning c# as I go)

these methods are on pages a in a folder called modules on pages called
along the lines of S3generalDB.cs

So my next question is can I do something like

price = myprice

and have a method that says

myprice = Convert.ToDecim al(reader["start_pric e"]).ToString("C",
NumberFormatInf o.CurrentInfo)

if should I put it at the top of the page , and how should I declare it

Sorry if this is too simple but I am really new to .net and C#

Regards

Wayne



"LW Irving" <li*****@coffs. com.au> wrote in message
news:ue******** ******@TK2MSFTN GP12.phx.gbl...
when I use the snippet below

price = "$" + reader["start_pric e"].ToString() + " to $" +
reader["end_price"].ToString();

the price is returned with 4 decimal places

I thought I could do; reader["start_pric e"].ToString("C") to format the string as currency and do away "$" + from the line

or reader["start_pric e"].ToString("00.0 0") to at least specify the decimal places

but niether work

What am I doing wrong

Regards

Wayne

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.543 / Virus Database: 337 - Release Date: 11/21/2003

Nov 15 '05 #9

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

Similar topics

16
5990
by: Christopher Benson-Manica | last post by:
I'm wondering about the best way to do the following: I have a string delimited by semicolons. The items delimited may be in any of the following formats: 1) 14 alphanum characters 2) 5 alphanums space 8 alphanums 3) 6 alphanums colon 8 alphanums 4) 5 alphanums colon 8 alphanums My task is to convert items in the third format to the first format, and items
6
2610
by: Donal McWeeney | last post by:
Hi, Is there a way to specify on the predefined format strings like P and N that you want displayed all the decimals in the number... for example 3 will display 3 2.1 will display 2.1 3.21 will display 3.21
4
2850
by: Chris Dunaway | last post by:
I have a table in the database with a phone number field. The phone number is stored without any punctuation (e. g. 9995551234). I wish to take that string and format it for display (e. g. (999) 555-1234). I know that I can use the .substring method of the string class to get the characters I want and format it: Dim s As String With strPhone
20
3706
by: MLH | last post by:
120 MyString = "How many copies of each letter do you need?" 150 MyVariant = InputBox(MyString, "How Many?", "3") If MyVariant = "2" Then MsgBox "MyVariant equals the string '2'" If MyVariant = 2 Then MsgBox "MyVariant also equals the value 2" 160 If MyVariant = "" Then HowManyCopies = 1 170 If Not IsNumeric(MyVariant) Then HowManyCopies = 1 MsgBox "OK. HowManyCopies has a value of " & CStr(HowManyCopies) 180 For i =...
15
3074
by: Fariba | last post by:
Hello , I am trying to call a mthod with the following signature: AddRole(string Group_Nam, string Description, int permissionmask); Accroding to msdn ,you can mask the permissions using pipe symbol .for example you can use something like this AddRole("My Group", "Test", 0x10000000|0x00000002);
7
3109
by: L. Scott M. | last post by:
Have a quick simple question: dim x as string x = "1234567890" ------------------------------------------------------- VB 6 dim y as string
5
2316
by: AMP | last post by:
Hello, I want to add some variables to a string and this isnt working. textBox1.Text="'BSL version='+ bslVerHi+ bslVerLo"; What am I doing wrong? Thanks Mike
0
3163
by: sehguh | last post by:
Hiya Folks, I am Currently using windows xp. Also using Visual Web Developer 2005 and Microsoft Sql server 2005. The main page consists of an aspx page and a master page. The page also consists of a label control(hidden when run in browser). Also an Sql data source control connected to database tables for a photo album. Also label web control ID=UserIdValue. Also a Details View control ID=dvPictureInsert Problem is how to work out...
8
3667
by: te509 | last post by:
Hi guys, does anybody know how to convert a long sequence of bits to a bit-string? I want to avoid this: '949456129574336313917039111707606368434510426593532217946399871489' I would appreciate a prompt reply because I have a python assessment to submit. Thanks, Thomas
3
3260
by: 6afraidbecause789 | last post by:
If able, can someone please help make a Where clause that strings together IDs in a multi-select listbox AND includes a date range. I wasn’t thinking when I used the code below that strings together the IDs of Clients from a multi-select listbox in an unbound text field, txtCriteria, on a form that is used to pick different reports. It appears that I now have so many clients that I’ve reached the 255 character limit in the txtCriteria...
0
8676
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8608
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9164
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9029
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8870
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7734
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.