473,659 Members | 3,553 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.0 0}"), but all I got was the characters
##0.00 displayed instead!

Actually the original code is like this:

row("Rate").ToS tring.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 1258
Hi,

Use a numberformatinf o. 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.Bindin gContext(DataGr id1.DataSource) ,
CurrencyManager )

Dim pd As System.Componen tModel.Property Descriptor =
cm.GetItemPrope rties()("Qty")

Dim ni As New System.Globaliz ation.NumberFor matInfo

ni.NumberDecima lDigits = 3

Dim colQty As New DataGridTextBox Column(pd, "f")

With colQty

..MappingName = "Col1"

..HeaderText = "Qty"

..Width = 75

..FormatInfo = ni

End With

Ken

------------------------------
<po******@alexs hirley.com> wrote in message
news:11******** *************@g 47g2000cwa.goog legroups.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.0 0}"), but all I got was the characters
##0.00 displayed instead!

Actually the original code is like this:

row("Rate").ToS tring.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").ToS tring & " (" & row("Rate").ToS tring & "%)"

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******@alexs hirley.com> wrote in message
news:11******** *************@g 47g2000cwa.goog legroups.com...
.. . .
I've tried to use:
number.tostring .format("##0.00 ")
or
number.tostring .format("{##0.0 0}"), 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
1920
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 come up as 02/07/04. as a consequence I can't get the right record selected. How do i ensure all references to dates are as in UK? My PC is ... I think correctly set up. This has driven me round the bend!!
10
3032
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 Runtime? I just purchased Office 2003 Professional. Is Access 2003 Runtime included with that or not? It APPEARS that the only way I can get Access 2003 Runtime is to
9
2239
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 the first int and &arr is a pointer to the whole array of 10 ints. Then why does sizeof(arr) gives 40 while sizeof(&arr) gives 4. Shouldn't is be the other way around.
2
2055
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 (non-.Net) if I wanted to fill a list it may look something like this: -------START CODE <%
4
4879
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 repsonse.redirect. My understanding was that the server.transfer method doesn't update the URL address bar. However, I've a situation that I'm a bit confused about and would appreciate any advice on why the following is occuring (i.e. why I'm obviously missing...
2
1052
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 specific, I allow users to select values from a dropdown list, and add them to a listbox. When the users selects a value from the dropdown list and clicks "add", the page posts back very quickly and adds the value into the listbox. This works as it...
4
1056
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.... ie newstring=format(oldstring,"????") What goes in as the format conversion to get the affect I want?
2
1335
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
9016
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 a way to convert a string like "1/2/2005" in a genuan date object which is needed for calculation. now once this is done I will create a another date object with today = datetime.datetime.now() and then see the difference between this today and...
0
8337
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
8748
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
8628
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
7359
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...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
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
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.