Thanks:  0
Likes:  0
Dislikes:  0

# Thread: Sort of truncate, but not really

1. ## Sort of truncate, but not really

Ive been battling with this for a couple of days. And I am on a tight schedule.

I have a variable that is sent from JAVA gui via corba to website. On Java the variable will always have 4 decimals after the period. On the website - no.

for example
if on the java gui its 23.0001, the website will have it 23.0001
if on the java gui its 3.5050, the website will have it as 3.505
if on the java gui its 3.5000, the website will have it as 3.5

and so on.

I have a headache for 2 days already trying to compare values from the gui to the website. I tried left, instr and looping thru the variables to make them the same. Cant seem to get this right and the time is ticking away.

Can anyone help?

2. ## Re: Sort of truncate, but not really

Try this

x = "3.5050"
y = "3.505"

if CDbl(x) = Cdbl(y)) then Msgbox "Equal"

3. ## Re: Sort of truncate, but not really

embarasing........

4. ## Re: Sort of truncate, but not really

Actually here is the problem.

x=4.91 - double
y="4.910001" - string

when you convert both to double, they dont match, obviously. So how to I truncate to the 4th decimal? I cant use Right function because I dont know what is the whole number is going to be - is it going to be 4.3333 or 14.3333. So how do I truncate 4 decimals after the point?

5. ## Re: Sort of truncate, but not really

x=4.91
y="4.910001"
If cStr(x) = Left(y,Len(cStr(x))) Then Msgbox "Equal" Else Msgbox "Not Equal"
If cdbl(x) = cdbl(Left(y,Len(x))) Then Msgbox "Equal" Else Msgbox "Not Equal"

6. ## Re: Sort of truncate, but not really

You can Use the Round Function

x = Round(x,"4") (Please check the Syntax)

Before that U change the x and y to Double

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.