vbscript help

  • Thread starter Thread starter Joe Shmoe
  • Start date Start date
J

Joe Shmoe

I took over someone's project and there are some glitches
in the program. I narrowed it down to the cdbl function.
There is a number in a variable with the value 148.10

after converting that to a double, the number is 148.1

These are really 2 different records, so things are
getting mixed up. I'm trying to figure out if the cdbl
function is necessary. anyways, converting a number with a
zero on the end to a double drops the zero. Is there some
way to keep it on?
 
Joe said:
I took over someone's project and there are some glitches
in the program. I narrowed it down to the cdbl function.
There is a number in a variable with the value 148.10

after converting that to a double, the number is 148.1

These are really 2 different records, so things are
getting mixed up. I'm trying to figure out if the cdbl
function is necessary. anyways, converting a number with a
zero on the end to a double drops the zero. Is there some
way to keep it on?

Hi - I used the search term "vbscript help" in Google and got about
505,000 links. Although you might get an answer here, I think it would
be more helpful for you to post in a forum dedicated to Visual Basic
scripting rather than in a newsgroup for an operating system. Also, I'm
sure that there must be an MS Visual Basic newsgroup. Here's a link to
a list of all the MS newsgroups:

http://aumha.org/nntp.htm

Good luck,

Malke
 
Joe said:
I took over someone's project and there are some glitches
in the program. I narrowed it down to the cdbl function.
There is a number in a variable with the value 148.10

after converting that to a double, the number is 148.1

These are really 2 different records, so things are
getting mixed up. I'm trying to figure out if the cdbl
function is necessary. anyways, converting a number with a
zero on the end to a double drops the zero. Is there some
way to keep it on?

Hi

You question is better asked in the microsoft.public.scripting.wsh or
microsoft.public.scripting.vbscript group.

Anyway, you could e.g. use the FormatNumber function:


iNumber = 148.1
iNumber = FormatNumber(iNumber, 2)
WScript.Echo iNumber


WSH 5.6 documentation (local help file) can be downloaded from here
if you haven't got it already:

http://msdn.microsoft.com/downloads/list/webdev.asp
 
Joe Shmoe said:
I took over someone's project and there are some glitches
in the program. I narrowed it down to the cdbl function.
There is a number in a variable with the value 148.10

after converting that to a double, the number is 148.1

So what's the problem? It's the same number, right?
These are really 2 different records, so things are
getting mixed up. I'm trying to figure out if the cdbl
function is necessary. anyways, converting a number with a
zero on the end to a double drops the zero. Is there some
way to keep it on?

You're converting a string to a number. The value of the number is one
hundred forty eight and one tenth. The zero on the end is immaterial.

You apparently want to convert the number back to a string and always
have the string representation have two decimal places. Look at
VBScript's "FormatNumber" function, that will allow you to format the
number exactly as you wish.
 
Back
Top