473,320 Members | 1,879 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,320 software developers and data experts.

string number format

when I use the snippet below

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

the price is returned with 4 decimal places

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

or reader["start_price"].ToString("00.00") to at least specify the decimal
places

but niether work

What am I doing wrong

Regards

Wayne
Nov 15 '05 #1
8 7100
I also tried
price = "$" + Convert.ToDecimal( reader["start_price"]).ToString("0.00") + "
to $" + Convert.ToDecimal( 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**************@TK2MSFTNGP12.phx.gbl...
when I use the snippet below

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

the price is returned with 4 decimal places

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

or reader["start_price"].ToString("00.00") 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.ToDecimal( 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**************@TK2MSFTNGP10.phx.gbl...
I also tried
price = "$" + Convert.ToDecimal( reader["start_price"]).ToString("0.00") + " to $" + Convert.ToDecimal( 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**************@TK2MSFTNGP12.phx.gbl...
when I use the snippet below

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

the price is returned with 4 decimal places

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

or reader["start_price"].ToString("00.00") 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_price"].ToString() + " to $" +
reader["end_price"].ToString();

the price is returned with 4 decimal places

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

or reader["start_price"].ToString("00.00") to at least specify the decimal
places

but niether work

What am I doing wrong


Firstly, we need to know what reader["start_price"] 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.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #5
djozy <an*******@discussions.microsoft.com> wrote:
Please,can you tell me,witch function converts integer to
string?


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

--
Jon Skeet - <sk***@pobox.com>
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.ToDecimal(Value)).ToString("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.ToDecimal(Value)).ToString("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**************@TK2MSFTNGP12.phx.gbl...
when I use the snippet below

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

the price is returned with 4 decimal places

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

or reader["start_price"].ToString("00.00") 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.ToDecimal(reader["start_price"]).ToString("0.00")
or
price = Convert.ToDecimal(reader["start_price"]).ToString("C",
NumberFormatInfo.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.ToDecimal(reader["start_price"]).ToString("C",
NumberFormatInfo.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**************@TK2MSFTNGP12.phx.gbl...
when I use the snippet below

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

the price is returned with 4 decimal places

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

or reader["start_price"].ToString("00.00") 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.ToDecimal(reader["start_price"]).ToString("C",
NumberFormatInfo.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.ToString("C", NumberFormatInfo.CurrentInfo)
// If you call price here now you will get $0.00
myprice = (decimal)myReader.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*************@TK2MSFTNGP11.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.ToDecimal(reader["start_price"]).ToString("0.00")
or
price = Convert.ToDecimal(reader["start_price"]).ToString("C",
NumberFormatInfo.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.ToDecimal(reader["start_price"]).ToString("C",
NumberFormatInfo.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**************@TK2MSFTNGP12.phx.gbl...
when I use the snippet below

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

the price is returned with 4 decimal places

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

or reader["start_price"].ToString("00.00") 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
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...
6
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...
4
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)...
20
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...
15
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...
7
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
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
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...
8
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...
3
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.