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

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
Asked:
Anjinsan5
  • 3
  • 3
  • 2
1 Solution
 
vb_jonasCommented:
Cint takes the integer of the number. A trick is to do it this way

newvalue = cint(value+0.5)
0
 
Ashish PatelCommented:
if there are 2 decimals then multiply it with 100 and if there are 3 then multiple by 1000
0
 
vb_jonasCommented:
Also - isn't there a round-function in VB6?

newvalue = round(value)
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

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


you could also do this:

stringvalue = replace(cstr(value),".","")
0
 
Anjinsan5Author 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
 
Anjinsan5Author 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
 
Anjinsan5Author Commented:
Great help!
0
 
Ashish PatelCommented:
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

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

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