Return decimal value

Nita

New member
Local time
Today, 14:44
Joined
Feb 14, 2020
Messages
19
Hi,

I have a query with a value in currency, I convert it to number.
I can't get only the decimals, can you help me?
I am using Access 2016
 
Not sure I understand the problem. Would the round function work?
 
Hi,
I want the decimals values.
I need both of the values in separated fields.
The value before the "," I know how to get, the value after is the problem.
For example 5,55 I have one field that returns 5 and want another to return 55.
Thank you
 
x - int(x)
 
Good lesson in floating point arithmitic and things to consider when doing something like this. May not get what you expect without some extra code.
Code:
.

Public Sub Test()
 Dim x As Double
 x = -123.345
 Debug.Print Abs(x) - Int(Abs(x))
End Sub

Public Sub Test2()
 Dim x As Double
 x = -123.345
 Debug.Print CDec(Abs(x)) - CDec(Int(Abs(x)))
End Sub
The first returns
0.344999999999999
The second returns
0.345
 
You will get the same result as Test2() if you substitute CDec() for CCur()

I'd be tempted to just declare x As Currency:
Code:
Public Sub Test3()
 Dim x As Currency
 x = -123.345
 Debug.Print Abs(x) - Int(Abs(x))
End Sub

In Immediate Window:
Code:
Test3
 0.345
 
Good lesson in floating point arithmitic and things to consider when doing something like this. May not get what you expect without some extra code.
Code:
.

Public Sub Test()
Dim x As Double
x = -123.345
Debug.Print Abs(x) - Int(Abs(x))
End Sub

Public Sub Test2()
Dim x As Double
x = -123.345
Debug.Print CDec(Abs(x)) - CDec(Int(Abs(x)))
End Sub
The first returns
0.344999999999999
The second returns
0.345
In that case, what I need is to return 345.
 
Currency defines a fixed-point number with exactly four decimal places. How many decimal places are then displayed is irrelevant and only a matter of display and interpretation. You can therefore use integer calculations immediately.
Code:
?123.345 * 10000 mod 10000
 3450

3450 / 10000 = 345 / 1000

Eberhard
 

Users who are viewing this thread

Back
Top Bottom