• Status: Solved
• Priority: Medium
• Security: Public
• Views: 4963

# Convert decimal value to whole number...

I am using an MSFLexgrid with 2 columns (each column formats the value to a different decimal place), and a textbox to edit the values.  The user types in a value (6 digit max) in each column which for column1 is automatically formatted to 3 decimal places (i.e. 123.456) and for column 2 the user selects desired decimal setting from a combo box.  What I need is to take the value entered in col 2 for each cell and send it as a whole number in a command instead of a decimal value (i.e if the user's value for col 2 is 1234.56 I need to send 123456).  I have tried the Cint function with no luck.
0
Anjinsan5
• 3
• 3
• 2
1 Solution

Commented:
Cint takes the integer of the number. A trick is to do it this way

newvalue = cint(value+0.5)
0

Commented:
if there are 2 decimals then multiply it with 100 and if there are 3 then multiple by 1000
0

Commented:
Also - isn't there a round-function in VB6?

newvalue = round(value)
0

Commented:
ah sorry... *must check my glasses, or answer questions when I'm not tired*

you could also do this:

stringvalue = replace(cstr(value),".","")
0

Author Commented:
Thanks for the replies so far...the problem i'm having is the user will select a decimal format of their choice from a combo box (options are ddddd.d, dddd.dd, ddd.ddd, dd.dddd, and d.ddddd) and whatever value they type into col 2 of the msflexgrid will automatically format according to their selection.  I did try the options you gave, however when I take the user's value and convert to whole number and send the value to a device it still reads as a decimal value.  Hope I didn't totally confuse anyone...
0

Author Commented:
Sorry vb jonas...I posted that last comment before you gave your latest solution.  Your idea worked great! Thanks so much for the help!
0

Author Commented:
Great help!
0

Commented:
or just do one simple thing as below

1. convert the value to string first by using CSTR(variable)
2. replace "." (period) with "" (blank) by using Replace(CSTR(variable), ".", "")
3. convert the value to long again by finally saying Clng("0" & Replace(CSTR(variable), ".", ""))

so  finally use this Clng("0" & Replace(CSTR(variable), ".", "")) for any level of decimal point number.
0

## Featured Post

• 3
• 3
• 2
Tackle projects and never again get stuck behind a technical roadblock.