473,654 Members | 3,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calculated Field/ Decimal Precision Help.... MS Access 2k

2 New Member
I am having an issue where I need to multiply a double value by a value with four decimal places within a calc field. However, it will only allow me to multiply by a whole number. "Invalid precision for a decimal" Suggestions?

If I reference a column in a table with the same number (37.8976) this works fine.

Example: Value: Avg(IIf([CAP OR FFS]="CAP" And ([MRTYPE] Like "*a*") And [HOSP_OR_OFFICE]="H",(([SumOfMRTYPE4_FA C]+[SumOfMRTYPE5_FA C])*37.8976),(IIf ([CAP OR FFS]="CAP" And ([MRTYPE] Like "*a*") And [HOSP_OR_OFFICE] Not Like "H",(([SumOfMRTYPE4]+[SumOfMRTYPE5])*37.8976),[SumOfAmt_REC]))))

When controlling the properties of the field in the query I can not specify decimal places, only General Number and Fixed data types with no precision control.
Oct 23 '08 #1
4 8137
ADezii
8,834 Recognized Expert Expert
I am having an issue where I need to multiply a double value by a value with four decimal places within a calc field. However, it will only allow me to multiply by a whole number. "Invalid precision for a decimal" Suggestions?

If I reference a column in a table with the same number (37.8976) this works fine.

Example: Value: Avg(IIf([CAP OR FFS]="CAP" And ([MRTYPE] Like "*a*") And [HOSP_OR_OFFICE]="H",(([SumOfMRTYPE4_FA C]+[SumOfMRTYPE5_FA C])*37.8976),(IIf ([CAP OR FFS]="CAP" And ([MRTYPE] Like "*a*") And [HOSP_OR_OFFICE] Not Like "H",(([SumOfMRTYPE4]+[SumOfMRTYPE5])*37.8976),[SumOfAmt_REC]))))

When controlling the properties of the field in the query I can not specify decimal places, only General Number and Fixed data types with no precision control.
You can use the Round() or FormatNumber() Functions to produce the desired number of Decimal Places. The following SQL Statements will multiply a Double Field ([MyDouble]) by 37.8976, and Round the results to 3 Decimal Places in a Calculated Field named [RetVal]. The Test Table used for this Demo is named tblTest, pretty ingenious, hey?
Expand|Select|Wrap|Line Numbers
  1. SELECT tblTest.MyDouble, Round([MyDouble]*37.8976,3) AS RetVal
  2. FROM tblTest;
Expand|Select|Wrap|Line Numbers
  1. SELECT tblTest.MyDouble, FormatNumber([MyDouble]*37.8976,3) AS RetVal
  2. FROM tblTest;
Oct 23 '08 #2
mshmyob
904 Recognized Expert Contributor
As always.

cheers,
Oct 23 '08 #3
NeoPa
32,568 Recognized Expert Moderator MVP
Try :
Expand|Select|Wrap|Line Numbers
  1. Value: Avg(IIf([CAP OR FFS]='CAP' And ([MRTYPE] Like '*a*'),IIf([HOSP_OR_OFFICE]='H',CDbl([SumOfMRTYPE4_FAC])+CDbl([SumOfMRTYPE5_FAC]),CDbl([SumOfMRTYPE4])+CDbl([SumOfMRTYPE5]))*37.8976,[SumOfAmt_REC]))
I added in CDbl() to convert the non double values where necessary. This is because the defaults are to convert to integral types when unspecified.
Oct 23 '08 #4
apellerin
2 New Member
Thank you! I'll give these a shot.
Oct 23 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

21
4518
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
17
6135
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number. "Decimal Number" sometimes serves to distinguish Base 10 numbers, eg "15", from Base 2 numbers, Eg "1111". At other times "Decimal Number" serves to differentiate a number from an integer. For the rest of this post I shall only use either...
6
10540
by: Peter Blatt | last post by:
Does 5 represent the total numer of digits (including the fractional portion) or only the number of places BEFORE the decimal point? Moreover does the number include the decimal point? Are there differences between the databases servers ? Peter
5
4046
by: John Bahran | last post by:
I am trying to use calculated fields in my query but all the results are zero ven when they're not. Please help. Thanks.
4
3073
by: hi | last post by:
I'm having major problem with multiplications in querys. E.g. Table 1 f1 Single f2 Single f1=1.12 f2=.2345 I create a query with just one field a:f1*f2 and I get
687
23321
by: cody | last post by:
no this is no trollposting and please don't get it wrong but iam very curious why people still use C instead of other languages especially C++. i heard people say C++ is slower than C but i can't believe that. in pieces of the application where speed really matters you can still use "normal" functions or even static methods which is basically the same. in C there arent the simplest things present like constants, each struct and enum...
3
3845
by: Amaryllis | last post by:
Hi again, I'm new to the world of communicating between VB.NET and AS/400, so I've been posting a lot of questions lately since no one else in the company has done anything like this before. Hopefully, this one is fairly simple. I'm trying to insert records into a table on the 400. I can insert into a packed field that has no decimal places and into the alphanumeric fields as well. Everything seems to translate except the values that...
2
6003
by: Unforgiven | last post by:
Hello All, I have the following query... SELECT Demographics.Full_Name, Demographics.Year_of_birth, Status.Status_OK, SUM(2004 - Demographics.Year_of_birth) AS Age FROM Demographics INNER JOIN Status ON Demographics.PrimaryKey = Status.PrimaryKey
11
2238
by: Pieter | last post by:
Hi, I'm having some troubles with my numeric-types in my VB.NET 2005 application, together with a SQL Server 2000. - I first used Single in my application, and Decimal in my database. But a Single with value 4.475 was converted to a Decimal with value 4.4749999999999996D. So after inserting and selecting it from the database I got another value than the original!
0
8379
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8294
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8494
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8596
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7309
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5627
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4297
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2719
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1597
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.