formatted numbers returned when they should not be.

A

Adrian Parker

I have tables that contain columns declared as numeric(18,6)

When i do the following vb code..

lstr_val = CStr(reader.Item("numeric_column_name"))

lstr_val contains a zero padded number.

e.g.

say I put 3.2 into the column, the string would contain 3.200000 when it was displayed.

However..this has only been a problem (I think) since framework 1.1 was installed.

Any ideas ?
 
E

EricJ

as to the couse no :/
as to a sollution
lstr_val = CStr(reader.Item("numeric_column_name")).trimend("0"c)

eric
 
A

Adrian Parker

:) yeah, solution is easy if I know it's a numeric column I'm reading, but unfortunately, I don't know at runtime whether it's a
numeric or a string field with training zeros in it, so I can't just unilaterally chop trailing zeros.
--
Adrian Parker


EricJ said:
as to the couse no :/
as to a sollution
lstr_val = CStr(reader.Item("numeric_column_name")).trimend("0"c)

eric
 
E

EricJ

if isnumeric(CStr(reader.Item("numeric_column_name"))) then
'you can also use the format function

format(CStr(reader.Item("numeric_column_name")),"###########################
##.###################")
end if

but you seem to know the column?

eric
Adrian Parker said:
:) yeah, solution is easy if I know it's a numeric column I'm reading,
but unfortunately, I don't know at runtime whether it's a
numeric or a string field with training zeros in it, so I can't just
unilaterally chop trailing zeros.
 
A

Adrian Parker

Unfortunately, I don't know the column type at runtime.. it could be a varchar or a numeric, all I know is the column name.. When it
just returned the 3.2 it worked fine, now it's adding the extra zeros it's causing a problem.

-Adrian
 
E

EricJ

1st you are converting to string 2nd you check if the string is numeric (i
fail to c the problem, but thats probably me)
it could help if you gie a list of different values that are returned (with
the type)

Adrian Parker said:
Unfortunately, I don't know the column type at runtime.. it could be a
varchar or a numeric, all I know is the column name.. When it
 
A

Adrian Parker

What we're doing is allowing users to select the columns they want to appear in a web form.. we're building the form up just knowing
the name of the columns.. the data could be anything, but was working perfectly ok using the CStr function to convert whatever it
was to a stirng.. now it isn't wokring.
I can't just remove trailing zeros because a varchar field could contain 1000.
 
E

EricJ

go for the format function then normally it should work, if not you could
have a look at formatNumber 2

eric


Adrian Parker said:
What we're doing is allowing users to select the columns they want to
appear in a web form.. we're building the form up just knowing
the name of the columns.. the data could be anything, but was working
perfectly ok using the CStr function to convert whatever it
 
C

Cor

Hi Eric and Adrian,

I think the problem is you both are not using upercases

:)))) just for fun what is above

If all fails, maybe this is a possibillity

lstrval = lstrval.Substring(0, lstrval.LastIndexOf(".") + 3)

Cor
 
E

EricJ

hi Cor :)

the question would be is there a . if there are no decimals? ;p

but it did make me think of something

if str.indexof(".") <> -1 then
strNew = str.trimEnd("0"c)
end if
 
A

Adrian Parker

Thanks for the responses guys, but I have no idea what data I'm getting back so can't use formatting to resolve the problem..

I have to find out why the either the CStr function or the reader.item() property has stopped returning what it did in the past.
 
A

Adrian Parker

I've upgraded to dotnet 2003 and therefore using framework 1.1 and it's still a problem.
 
K

keyur shah

1) You have the column numeric scale and precision that is responsible
for the return value
2) You are retrieving it after converting it to str this is the complete
issue...

Store it in a int or number variable... it would resolve ur issue.


Keyur Shah
Verizon Communications
732-423-0745
 
K

Kevin Yu [MSFT]

Thanks all for your response.

Hi Adrian,

I think you can first put the value into an float variable. You can use
ToString() method to convert the float to whatever type you wish, as
ToString has an overload like ToString(string).

Please refer to the following link for more information.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemsingleclasstostringtopic.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemGlobalizationNumberFormatInfoClassTopic.asp

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| From: keyur shah <[email protected]>
| References: <[email protected]>
| X-Newsreader: AspNNTP 1.50 (ActionJackson.com)
| Subject: Re: formatted numbers returned when they should not be.
| Mime-Version: 1.0
| Content-Type: text/plain; charset="us-ascii"
| Content-Transfer-Encoding: 7bit
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.adonet
| Date: Wed, 05 Nov 2003 16:37:31 -0800
| NNTP-Posting-Host: actionjackson133.dsl.frii.net 216.17.147.133
| Lines: 1
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:65571
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| 1) You have the column numeric scale and precision that is responsible
| for the return value
| 2) You are retrieving it after converting it to str this is the complete
| issue...
|
| Store it in a int or number variable... it would resolve ur issue.
|
|
| Keyur Shah
| Verizon Communications
| 732-423-0745
|
|
| Don't just participate in USENET...get rewarded for it!
|
 
A

Adrian Parker

No, the problem is that they seem to have changed how it works between framework 1.0 and 1.1.
 
E

EricJ

we know to little of all your possible values

give me an example where this can't work

if str.indexof(".") <> -1 and isnumeric(str) then
strNew = str.trimEnd("0"c)
end if
 
K

Kevin Yu [MSFT]

Hi Adrian,

The behavior of Cstr() has changed a bit from VS .net 2002 to VS .net 2003.
You can resolve this by using the following code:

dim s as single = reader.Item("numeric_column_name")
lstr_val = Cstr(s)

This works both in 2002 and 2003.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| From: "Adrian Parker" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: Re: formatted numbers returned when they should not be.
| Date: Thu, 6 Nov 2003 06:53:54 -0000
| Lines: 19
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.adonet
| NNTP-Posting-Host: 82-37-130-6.cable.ubr01.telf.blueyonder.co.uk
82.37.130.6
| Path:
cpmsftngxa06.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:65590
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| No, the problem is that they seem to have changed how it works between
framework 1.0 and 1.1.
|
| > 1) You have the column numeric scale and precision that is responsible
| > for the return value
| > 2) You are retrieving it after converting it to str this is the complete
| > issue...
| >
| > Store it in a int or number variable... it would resolve ur issue.
| >
| >
| > Keyur Shah
| > Verizon Communications
| > 732-423-0745
| >
| >
| > Don't just participate in USENET...get rewarded for it!
|
|
|
 
A

Adrian Parker

Ach! ok, so we will have to rewrite it all, given we were relying on cstr
returing an already truncated string when dealing with fields of unknwon
datatype. Is there any way of determining the datatype of a resultset column
in an oldbdatareader ?

-Adrian
 
K

Kevin Yu [MSFT]

Hi Adrian,

You can get the data type by calling GetType() on an object. For example,
you can use datareader["column"].GetType() to get the type of the value in
the column.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| From: "Adrian Parker" <[email protected]>
| References: <[email protected]>
<[email protected]>
<#[email protected]>
<[email protected]>
| Subject: Re: formatted numbers returned when they should not be.
| Date: Fri, 7 Nov 2003 08:21:47 -0000
| Lines: 69
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.adonet
| NNTP-Posting-Host: 82-37-130-6.cable.ubr01.telf.blueyonder.co.uk
82.37.130.6
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:65729
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| Ach! ok, so we will have to rewrite it all, given we were relying on cstr
| returing an already truncated string when dealing with fields of unknwon
| datatype. Is there any way of determining the datatype of a resultset
column
| in an oldbdatareader ?
|
| -Adrian
|
| > Hi Adrian,
| >
| > The behavior of Cstr() has changed a bit from VS .net 2002 to VS .net
2003.
| > You can resolve this by using the following code:
| >
| > dim s as single = reader.Item("numeric_column_name")
| > lstr_val = Cstr(s)
| >
| > This works both in 2002 and 2003.
| >
| > Kevin Yu
| > =======
| > "This posting is provided "AS IS" with no warranties, and confers no
| > rights."
| >
| > --------------------
| > | From: "Adrian Parker" <[email protected]>
| > | References: <[email protected]>
| > <[email protected]>
| > | Subject: Re: formatted numbers returned when they should not be.
| > | Date: Thu, 6 Nov 2003 06:53:54 -0000
| > | Lines: 19
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <#[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.adonet
| > | NNTP-Posting-Host: 82-37-130-6.cable.ubr01.telf.blueyonder.co.uk
| > 82.37.130.6
| > | Path:
| >
cpmsftngxa06.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
| > phx.gbl!TK2MSFTNGP11.phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.adonet:65590
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
| > |
| > | No, the problem is that they seem to have changed how it works between
| > framework 1.0 and 1.1.
| > |
| > | > | > 1) You have the column numeric scale and precision that is
responsible
| > | > for the return value
| > | > 2) You are retrieving it after converting it to str this is the
complete
| > | > issue...
| > | >
| > | > Store it in a int or number variable... it would resolve ur issue.
| > | >
| > | >
| > | > Keyur Shah
| > | > Verizon Communications
| > | > 732-423-0745
| > | >
| > | >
| > | > Don't just participate in USENET...get rewarded for it!
| > |
| > |
| > |
| >
|
|
|
 
A

Adrian Parker

Ah, ok Kevin, many thanks.

-Adrian


Kevin Yu said:
Hi Adrian,

You can get the data type by calling GetType() on an object. For example,
you can use datareader["column"].GetType() to get the type of the value in
the column.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| From: "Adrian Parker" <[email protected]>
| References: <[email protected]>
<[email protected]>
<#[email protected]>
<[email protected]>
| Subject: Re: formatted numbers returned when they should not be.
| Date: Fri, 7 Nov 2003 08:21:47 -0000
| Lines: 69
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.adonet
| NNTP-Posting-Host: 82-37-130-6.cable.ubr01.telf.blueyonder.co.uk
82.37.130.6
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:65729
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| Ach! ok, so we will have to rewrite it all, given we were relying on cstr
| returing an already truncated string when dealing with fields of unknwon
| datatype. Is there any way of determining the datatype of a resultset
column
| in an oldbdatareader ?
|
| -Adrian
|
| > Hi Adrian,
| >
| > The behavior of Cstr() has changed a bit from VS .net 2002 to VS .net
2003.
| > You can resolve this by using the following code:
| >
| > dim s as single = reader.Item("numeric_column_name")
| > lstr_val = Cstr(s)
| >
| > This works both in 2002 and 2003.
| >
| > Kevin Yu
| > =======
| > "This posting is provided "AS IS" with no warranties, and confers no
| > rights."
| >
| > --------------------
| > | From: "Adrian Parker" <[email protected]>
| > | References: <[email protected]>
| > <[email protected]>
| > | Subject: Re: formatted numbers returned when they should not be.
| > | Date: Thu, 6 Nov 2003 06:53:54 -0000
| > | Lines: 19
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <#[email protected]>
| > | Newsgroups: microsoft.public.dotnet.framework.adonet
| > | NNTP-Posting-Host: 82-37-130-6.cable.ubr01.telf.blueyonder.co.uk
| > 82.37.130.6
| > | Path:
| >
cpmsftngxa06.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
| > phx.gbl!TK2MSFTNGP11.phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.adonet:65590
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
| > |
| > | No, the problem is that they seem to have changed how it works between
| > framework 1.0 and 1.1.
| > |
| > | > | > 1) You have the column numeric scale and precision that is
responsible
| > | > for the return value
| > | > 2) You are retrieving it after converting it to str this is the
complete
| > | > issue...
| > | >
| > | > Store it in a int or number variable... it would resolve ur issue.
| > | >
| > | >
| > | > Keyur Shah
| > | > Verizon Communications
| > | > 732-423-0745
| > | >
| > | >
| > | > Don't just participate in USENET...get rewarded for it!
| > |
| > |
| > |
| >
|
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top