|
-
Feb 7th, 2006, 10:32 AM
#1
Thread Starter
Hyperactive Member
Round Down in Access
Everytime I enter currency in a currency textbox. It automatically rounds up. For instance, $172.845 will round to $172.85. How do I make it round down instead? Anyone know?
-
Feb 7th, 2006, 11:05 AM
#2
Re: Round Down in Access
u need to calc it on your own
offhand the only way I can remember how to do this is actually turn the number into a string then back
(FYI: The actual value is still 172.845 but access rounds up for display purposes only. when the number is used for calcs or called back up.. it is in its original form with as many decimals as it had originally)
VB Code:
Dim NUM As Currency
Dim TMP As Double
TMP = 172.845
NUM = CCur(Left(CStr(tmp),InStr(CStr(tmp),".")+2))
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Feb 7th, 2006, 12:21 PM
#3
Thread Starter
Hyperactive Member
Re: Round Down in Access
Can you send me an example. It's driving me nuts!
-
Feb 7th, 2006, 12:30 PM
#4
Re: Round Down in Access
If this is in an Access form textbox then just set the Decimal Places property to 3 or more depending on the accuracy you desire.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Feb 7th, 2006, 12:38 PM
#5
Re: Round Down in Access
The table below the form will also need to be changed as the issue could be at this point.. (InputMask, Format for example)
Danny
Never Think Impossible
If you find my answer helpful then please add to my reputation
-
Feb 7th, 2006, 12:41 PM
#6
Thread Starter
Hyperactive Member
Re: Round Down in Access
It is an Access form textbox. I want two decimals. But it's rounding 43.455 to 43.46 and even if the number is 43.455 I want it to truncate and show 43.45
-
Feb 7th, 2006, 12:42 PM
#7
Thread Starter
Hyperactive Member
Re: Round Down in Access
 Originally Posted by dannymking
The table below the form will also need to be changed as the issue could be at this point.. (InputMask, Format for example)
Currency format with no input mask
-
Feb 7th, 2006, 12:44 PM
#8
Re: Round Down in Access
Check your underlying table to see what the overall properties are for the field to which this text box is bound.
If no joy there then you will have to use vba code to capture the value as it is entered into the textbox (either through record navigation or user interactio) and display it as a string instead. This way you can keep the two decimal places and lose the additional.. But it is bad design and will ultimately lead to further problems.
Danny
Never Think Impossible
If you find my answer helpful then please add to my reputation
-
Feb 7th, 2006, 12:46 PM
#9
Re: Round Down in Access
There is also a Format property for the textbox which will allow you to create a custom display format truncating the third or more decimal place without rounding.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Feb 7th, 2006, 12:46 PM
#10
Re: Round Down in Access
Cross post..
change the currency to number with field size of single instead.
Danny
Never Think Impossible
If you find my answer helpful then please add to my reputation
-
Feb 7th, 2006, 12:47 PM
#11
Re: Round Down in Access
Good idea Danny. That will retain the precision of the original number. Then you can format it however you want without it rounding at all.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Feb 8th, 2006, 06:30 AM
#12
Thread Starter
Hyperactive Member
Re: Round Down in Access
 Originally Posted by RobDog888
Good idea Danny. That will retain the precision of the original number. Then you can format it however you want without it rounding at all. 
So now the original number stays the same, great. But how do I format it to just show 45.26 instead of showing 45.26745674??
-
Feb 8th, 2006, 06:34 AM
#13
Thread Starter
Hyperactive Member
Re: Round Down in Access
How do I use this: I tried but can't get it working. Sounds like what I want to do. I want to ignore any numbers entered after the 2 decimal places.
To round or truncate numbers to two decimal places, create a new module and add the following functions.
VB Code:
'******************************************************
' Declarations section of the module
'******************************************************
Option Explicit
Const Factor = 100
'=====================================================
' TruncAU is designed to be added to the
' AfterUpdate property on a form control.
'=====================================================
Function TruncAU(X As Control)
X = Int(X * Factor) / Factor
End Function
'=====================================================
' RoundCC and TruncCC are designed to be used in
' expressions and calculated controls on forms and reports.
'=====================================================
Function RoundCC(X)
RoundCC = Int (X * Factor + 0.5) / Factor
End Function
Function TruncCC(X)
TruncCC = Int (X * Factor) / Factor
End Function
Examples of Using the Round and Truncate Functions
Example 1
Use the TruncAU() function to the AfterUpdate property of a form:
1. Open the database
2. Create a new module called Rounding, and type the procedures in the preceding section.
3. Open your form in Design view, and add the TruncAU() function to the AfterUpdate property of the field (NUM)
Form: Form1
--------------
VB Code:
Control Name: NUM
AfterUpdate: =TruncAU([NUM])
If a user accidentally enters $23.055 instead of $23.05, the TruncAu() function catches the mistake and changes the value to $23.05.
Last edited by vonoventwin; Feb 8th, 2006 at 06:38 AM.
-
Feb 8th, 2006, 06:44 AM
#14
Thread Starter
Hyperactive Member
Re: Round Down in Access
This is exactly what I want to do Truncate. I don't want the extra numbers typed in. just the first 2 after the decimal (ex: 45.6577758, I want 45.65)
TRUNCATE
(v.) To cut off the end of something. Usually, the term is used to describe a type of rounding of floating-point numbers. For example, if there are too few spaces for a long floating-point number, a program may truncate the number by lopping off the decimal digits that do not fit: 3.14126 might be truncated to 3.14. Note that truncation always rounds the number down. If the number 1.19999 is truncated to one decimal digit, it becomes 1.1, not 1.2.
-
Feb 9th, 2006, 04:43 AM
#15
Re: Round Down in Access
Code:
strVar="45.553225" 'or variable of number
debug.print left(strVar,instr(1,strVar,".")+2)
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Mar 5th, 2006, 03:35 PM
#16
New Member
Re: Round Down in Access
This works for me:
Code:
Function RoundDown(dVal As Double, Decimals As Integer) As Double
Dim Factor As Double, fVal As Double
Dim iVal As Integer
Factor = Exp(Log(10) * Decimals)
fVal = dVal * Factor
iVal = Int(fVal)
RoundDown = iVal / Factor
End Function
Use it in an AfterUpdate event.
There are two kinds of person, the ones that think there are two kinds of person, and the ones that know better than that
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|