Hi

24sharon

Registered User.
Local time
Today, 06:58
Joined
Oct 5, 2004
Messages
147
I have a decimal number

I want to recived just the numbers after the "."

for example

100.26 >>> 26
1022.5 >>>5
10>>>0

I try with

num = "300.25"
d = num - int(num)
but its not good becuse its get "0.25" and I want just "25"

thank for any idea...
 
Number

Try this:

=Right([yournumber],2)

Don't forget to replace "yournumberfield" with the actual field in which the number is stored.

Good Luck
 
no

first of all thanks!

if the number is 102.1 or just 102, its not good

I try now:
num = 100.1
d = 100*(num - int(num))

not eligant but work

Thanks! :)
 
Number

I was thinking that if you just want the number after the decimal as you said, you can set the property of the box that holds the number: Decimal Places = 2.
 
Try:

num = 100.1
d = CInt(Mid(CStr(num), InStr(CStr(num), ".") + 1))

If num can already be an integer then you just need to add a check of the instr first i.e.

If InStr(CStr(num), ".") = 0 Then
d = 0
Else
d = CInt(Mid(CStr(num), InStr(CStr(num), ".") + 1))
End If
 
Last edited:
trucktime - DO NOT use string functions on numeric values without first converting them to strings, even Help will tell you that they may not return the expected results.

Here is a simple solution.
Mid(cstr(CCur(Num) - Int(Num)),3)

I used the CCur() function because I wanted to avoid any potential problems with floating point errors. Type the following in the immediate window to see what I mean.

print 10.1 - 10
9.99999999999996E-02
 
Pat Hartman

Thanks alot.

Dont belive but I understand :p
 
Use a format conversion first. Then use InStr to locate the decimal point. Then use a RIGHT function to strip out the digits. Remember that the InStr returns the position of the decimal point, so it might be included in what you select. Play with it a bit. The only problem you would have is if the number is exact, in which case the decimal point can be omitted. In which case InStr won't find it.
 
sorry

I didn't get yet the answer!

here the example

I'll happy with any Idea

I want to recive 2 len after the decimal point
10.9 >>> 90
10>>>00
10.07>>>07
0.1>>>10
 

Attachments

24Sharon,

Both Pat and myself have given you a formula to extract the decimal part of a number. Although my attempt takes up more code..... :rolleyes: .
(Note: The CInt() in my code is not needed since it seems you want the output as a string).

Both give:

10.07 >> 07
10.9 >> 9

Hence you can use the LEFT function to see if the first character is a '0' and if not convert the output to a number, then *10 to get:

10.9 >> 9 >> 90.

And then presumably convert it back to a string.....

What would you expect the result to be if the input is 10.123 ?
 
What about

SomeField = Left(Replace((CCur([MyField]) - CInt([MyField])) & 0, "0.", ""), 2)

10.123

(CCur([MyField]) - CInt([MyField])) & 0 = 0.1230

Replace((CCur([MyField]) - CInt([MyField])) & 0, "0.", "") = 123

Left(Replace((CCur([MyField] & 0) - CInt([MyField])) & 0, "0.", ""), 2) = 12

10.1

(CCur([MyField]) - CInt([MyField])) & 0 = 0.10
Replace((CCur([MyField]) - CInt([MyField])) & 0, "0.", "") = .10
Left(Replace((CCur([MyField] & 0) - CInt([MyField])) & 0, "0.", ""), 2) = 10
 
You guys are getting yourselves all wrapped up in your underwear If you want two digits, the following converts a decimal value to a whole number and the format() adds a leading zero if necessary. The result is a string because that is what the Format() function returns. If there are more than 2 decimal digits present, the result is rounded to 2 places.

Format((ccur(Num) - int(Num)) * 100, "00")

Your first example showed single digits for 1022.5. You asked for 5 rather than 50. What is it you are trying to represent?
 
Realised on the bus this morning that my previous idea won't work since
it would give:

10.45 >> 45 >> 450.

As usual Pat has cornered the most important question.

'Sucuse me now I have some Y-Fronts to disentangle myself from :D
 
Pat

Format((ccur(Num) - int(Num)) * 100, "00")

do the work....

thanks alot for your time :)
 

Users who are viewing this thread

Back
Top Bottom