473,326 Members | 2,192 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,326 software developers and data experts.

Confused about format

Hi

I have a decimal numbers showing up on my datagrid that is displaying
lots of trailing zeros in the listbox.

i.e. 1.000100
or 1.000000

I want to get rid of all the trailing zeros (I don't want to do any
rounding).

I've tried to use:
number.tostring.format("##0.00")
or
number.tostring.format("{##0.00}"), but all I got was the characters
##0.00 displayed instead!

Actually the original code is like this:

row("Rate").ToString.Format("##0.00")

Where "rate" is a decimal (it's actually a percentage).

I'm very confused! Can you help?

Cheers!

Alex

Nov 21 '05 #1
4 1242
Hi,

Use a numberformatinfo. This is how to get a datagrid to display 3
digits after the decimal. Place this in your tablestyle for the grid.

Dim cm As CurrencyManager = CType(Me.BindingContext(DataGrid1.DataSource),
CurrencyManager)

Dim pd As System.ComponentModel.PropertyDescriptor =
cm.GetItemProperties()("Qty")

Dim ni As New System.Globalization.NumberFormatInfo

ni.NumberDecimalDigits = 3

Dim colQty As New DataGridTextBoxColumn(pd, "f")

With colQty

..MappingName = "Col1"

..HeaderText = "Qty"

..Width = 75

..FormatInfo = ni

End With

Ken

------------------------------
<po******@alexshirley.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
Hi

I have a decimal numbers showing up on my datagrid that is displaying
lots of trailing zeros in the listbox.

i.e. 1.000100
or 1.000000

I want to get rid of all the trailing zeros (I don't want to do any
rounding).

I've tried to use:
number.tostring.format("##0.00")
or
number.tostring.format("{##0.00}"), but all I got was the characters
##0.00 displayed instead!

Actually the original code is like this:

row("Rate").ToString.Format("##0.00")

Where "rate" is a decimal (it's actually a percentage).

I'm very confused! Can you help?

Cheers!

Alex
Nov 21 '05 #2
Thanks Ken for your reply

I think I was being unclear.

This is what I want is this to happen:

Decimal displayed in datagrid = 1.234000, decimal I actually want
displayed = 1.234
Decimal displayed in datagrid = 1.234500, decimal I actually want
displayed = 1.2345
Decimal displayed in datagrid = 1.234560, decimal I actually want
displayed = 1.23456
Decimal displayed in datagrid = 1.234567, decimal I actually want
displayed = 1.234567

The actual code I am using is:
li.text = row("Name").ToString & " (" & row("Rate").ToString & "%)"

which at the moment is an item in a listbox that is displaying
something like: "Francs (1.234000%)"
I actually want it displayed as "Francs (1.234%)"

I need to get rid of the trailing zeros which are being displayed,
rather than just display or round up/down to 3 digits.

Thanks

Alex

Nov 21 '05 #3
<po******@alexshirley.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
.. . .
I've tried to use:
number.tostring.format("##0.00")
or
number.tostring.format("{##0.00}"), but all I got was the characters
##0.00 displayed instead!


Shouldn't that be

number.ToString("##0.00")

ToString() returns a String, (hopefully) containing the formatted
number. When you call Format on this /String/ value, the masking
characters you can use are /different/ (I think "@" is about the only
one that still works).

HTH,
Phill W.
Nov 21 '05 #4
Thanks Phil

That didn't work for me either. I was very surprised I couldn't get rid
of these trailing zeros easily. I ended up writing my own workaround,
inefficient I guess but effective.

--------------------------------------------------------------------------------------------------------

Function notrailingzeros(ByVal strIn As String) As String

Dim i As Integer
For i = Len(strIn) To 1 Step -1
If Mid(strIn, i, 1) <> "0" Then Exit For
Next

If Mid(strIn, i, 1) = "." Then
Return Mid(strIn, 1, i) & "0"
Else
Return Mid(strIn, 1, i)
End If

End Function

--------------------------------------------------------------------------------------------------------

Cheers

Alex

Nov 21 '05 #5

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

Similar topics

4
by: John M | last post by:
Hi, I have spent some time trying to sort out a date problem (see mail an hour or so ago) and am now getting to see what the problem is. If I present today's date as 07/02/2004 in a search it...
10
by: Lauren Wilson | last post by:
Ok I have searched the MS website for info on this. I am totally confused. If I want to deploy an Access 2003 app and allow my users to run it using Access 2003 Runtime, where do I get the...
9
by: vijay | last post by:
Hello, I am new to C Programming and just started reading K&R. I was about to finish the pointers chapter but got very confused with: 1. int arr; >From what I have read, arr is a pointer to...
2
by: Daniel | last post by:
I'm new to .Net and all of its abilities so I hope this makes sense. Basically I'm confused on when is the appropriate time to use web forms controls vs. regular HTML. For example in ASP...
4
by: Bob H | last post by:
Hi, I'm aware of the different ways to pass variables between ASP.Net pages. For pages that need to pass a variable, we're using the server.transfer method. For others, we're using...
2
by: Moe | last post by:
Hello, I am very confused. Here is my situation: I have a web form with a few fields in place that are used as search criteria for a SQL database. Since I want the search criteria to be...
4
by: Simon Verona | last post by:
I'm a little confused I have a string that contains a number eg 11 that I want to format into a 4 character string with leading zeros ie 0011 I guess I need to use the "format" function.... ...
2
by: shapper | last post by:
Hello, I am completely confused in relation to Themes and CssClass in Asp.Net 2.0. Consider a custom control (MyControl) that I am creating which composed by: Panel_01 Table_01
6
by: krishnakant Mane | last post by:
hello, I am strangely confused with a date calculation problem. the point is that I want to calculate difference in two dates in days. there are two aspects to this problem. firstly, I can't get...
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
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: 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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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
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
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.