Convert decimal digit to integer

H

Howard31

Hi All,

I have the value 1.0020 in a cell, I want to assign the second right decimal
(2) to an integer variable, how do I do that?

Any help will be very much appreciated
 
R

Rick Rothstein

Whoops.... what I posted is not what you asked for. Your actual question is
a little strange. When dealing with floating point numbers, one rarely needs
to know a digit measure in from the end; rather, one usually wants to know
the digit so-many-positions in from the decimal point. The reason is because
"true numbers" do not have trailing zeroes, only string representations of
numbers can hold trailing zeroes. So I'm not really sure you want what you
asked for. Anyway, consider these...

Second digit from the end of a String value
========================================
Variable = Mid(StringNumber, Len(StringNumber) - 1, 1)

Third digit in from decimal point
========================================
Variable = Int(1000 * Number) Mod 10
 
R

Robert Crandal

How's this for a crazy solution:

Dim x as Integer

x = Left(Right(Sheet1.Range("A1").Text, 2), 1)

I think that returns what u want??
 
R

Robert Crandal

Oh, my mistake..... I was assuming that your decimal
digit was stored in Cell A1. So, if your decimial number
is stored in A1, then that code will work and it will save
the value in variable x!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top