Insert a decimal

K

Ken Sheridan

Are you saying you want to take an integer of variable length e.g. 1234567
and return 12.34567? If so one way would be:

NewNumber = OriginalNumber/10^(Int(log(OriginalNumber)/log(10))-1)

Ken Sheridan
Stafford, England
 
K

Ken Sheridan

PS: It would also work if the original number is a floating point number.

Ken Sheridan
Stafford, England
 
J

John W. Vinson

how do I insert a decimal 2 spaces from the left?

What's the context? Do you want to take 3145 and get 31.45, 22458712 and get
22.458712 and so on? What's the datatype of the field?

John W. Vinson [MVP]
 
H

helpme

Thank you everyone for your feedback. For instance it currently is 1234567
however it should be 12345.67. Another example is 123400 it should read
1234.00. It is currently saved as a text file.
 
D

Douglas J. Steele

That's two digits from the right, not from the left, so it's simpler than
Ken's suggestion.

All you need to do is divide the number by 100.
 
J

Jamie Collins

That's two digits from the right

All you need to do is divide the number by 100.

Actually, I think they may want to multiply by 0.01 e.g.

SELECT 1234567 / 100 AS float_value, TYPENAME(1234567 / 100) AS
float_type,
1234567 * 0.01 AS decimal_value, TYPENAME(1234567 * 0.01) AS
decimal_type

In my experience, when someone specifies 'decimal' they are interested
in exact values. Dividing by 100 returns an approximate type.

Jamie.

--
 
Top