Return decimal value (1 Viewer)

Nita

New member
Local time
Today, 00:19
Joined
Feb 14, 2020
Messages
5
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
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 19:19
Joined
May 21, 2018
Messages
2,810
Not sure I understand the problem. Would the round function work?
 

Nita

New member
Local time
Today, 00:19
Joined
Feb 14, 2020
Messages
5
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
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 19:19
Joined
May 21, 2018
Messages
2,810
x - int(x)
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 19:19
Joined
May 21, 2018
Messages
2,810
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
 

cheekybuddha

Registered User.
Local time
Today, 00:19
Joined
Jul 21, 2014
Messages
199
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
 

Nita

New member
Local time
Today, 00:19
Joined
Feb 14, 2020
Messages
5
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.
 

ebs17

Member
Local time
Today, 01:19
Joined
Feb 7, 2020
Messages
64
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 (Users: 0, Guests: 1)

Top Bottom