Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing Decimal

Status
Not open for further replies.

tekvaio

Programmer
Jun 6, 2005
4
US
Decimal
I'm in need of a script that will remove the decimal point of a number. For example: 13.22 -->> 1322 or 13.2 -->>13.20 or 13 -->> 1300 I'm unsure on how to do this.
Submitted by tekvaio (Programmer) on Jun 6, 2005
 
strNew = Replace(strOld, ".", "")

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Why not simply newValue=CLng(100*oldValue) ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
With that I think you would need to count the digits after the decimal to determine what to multiply by.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
This is what I used:
dim sourcetype
dim targettype

'Read in the source field
sourcetype = Records("[PersonInstruction!Instruction!Amount!AmountValue]Fixed").Fields("Value")
targetype = sourcetype * 100

targettype

it worked, it did not display any decimal points.
Thanks
TV
 
As long as your data never goes past the hundreths position.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
If you know that the data will always be numbers potentially with a decimal then you could do
strNew = Replace(strOld, ".", "")

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
TomThumbKP, surely CLng converts the number to a Long.

13.23456 * 100 = 1323.456

CLng(1323.456) = 1323

but CLng(1323.546) = 1324

To avoid rounding Fix(1323.546) = 1323

Hope this helps.
 
It is possible that I do not understand the end result, but I thought the desired result was to take any number that is provided and remove the decimal point from it. If that is the desired result, then this should work:

Replace(sourcetype, ".", "")

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
The Desired result is to have a implied decimal right justified... Must contain the same numbers(no rounding) 1222.33 -> 122233 or 1222.333 -> 1222333
Multiplying by 100 will only be correct for values with a hundreth of a decimal
 
The replace solution that I gave will do that.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Try this.
[tt]a=123456.7890123456
n=16 'fixed length
b=left(replace(a,".","")&string(n,"0"),n)
wscript.echo b
[/tt]
string is used for "big" number case.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top