473,804 Members | 3,058 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Metric Conversion

Howdy all

Im trying to do a fairly accurate metric conversion
between:

inches
feet
yards

Im pretty sure that i have the right number for conversion
between length type.

I have no problem switching between metric length(mm,cm,m)

When im trying to switch between imperial system, i run
into some accuracy problem. Feet and inches are fine, but
i have some problem with yards.

12 inches = 1 feet
1 feet = 12 inches
1 feet = 0.3333... yards
0.333... yards = 11.88 inches
0.333... yards = 0.999 feet

you get the point...

How can i keep the accuracy with out rounding
Nov 20 '05 #1
7 3753
El Camino,

Off the top of my head; In your functions that do the conversions you can
create a rounding rule that states if the number is within a specified unit
of a whole number then you can round up or round down. Try using the Mod
function for this and analyze the remainder.

Dan
"El Camino" <an*******@disc ussions.microso ft.com> wrote in message
news:0d******** *************** *****@phx.gbl.. .
Howdy all

Im trying to do a fairly accurate metric conversion
between:

inches
feet
yards

Im pretty sure that i have the right number for conversion
between length type.

I have no problem switching between metric length(mm,cm,m)

When im trying to switch between imperial system, i run
into some accuracy problem. Feet and inches are fine, but
i have some problem with yards.

12 inches = 1 feet
1 feet = 12 inches
1 feet = 0.3333... yards
0.333... yards = 11.88 inches
0.333... yards = 0.999 feet

you get the point...

How can i keep the accuracy with out rounding

Nov 20 '05 #2
"El Camino" <an*******@disc ussions.microso ft.com> schrieb
Howdy all

Im trying to do a fairly accurate metric conversion
between:

inches
feet
yards

Im pretty sure that i have the right number for conversion
between length type.

I have no problem switching between metric length(mm,cm,m)

When im trying to switch between imperial system, i run
into some accuracy problem. Feet and inches are fine, but
i have some problem with yards.

12 inches = 1 feet
1 feet = 12 inches
1 feet = 0.3333... yards
0.333... yards = 11.88 inches
0.333... yards = 0.999 feet

you get the point...

How can i keep the accuracy with out rounding

Accuracy will always be limited because any data type consumes a limited
amount of memory. Maybe using the Decimal data type can help you.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
Use a scaler, or ratio method. That is set a numerator and a denominator and
to the math on the final value:

double dScale(double dVal, double dNumerator, double dDenominator)
{
return (dVal * dNumerator) / dDenominator;
}
In this way you'll always get the precision of the system with no
intermediate rounding errors.

This is a trick often used in Forth, and embedded systems where floating
point is expensive in CPU and code space and hardware.
"El Camino" <an*******@disc ussions.microso ft.com> wrote in message
news:0d******** *************** *****@phx.gbl.. .
Howdy all

Im trying to do a fairly accurate metric conversion
between:

inches
feet
yards

Im pretty sure that i have the right number for conversion
between length type.

I have no problem switching between metric length(mm,cm,m)

When im trying to switch between imperial system, i run
into some accuracy problem. Feet and inches are fine, but
i have some problem with yards.

12 inches = 1 feet
1 feet = 12 inches
1 feet = 0.3333... yards
0.333... yards = 11.88 inches
0.333... yards = 0.999 feet

you get the point...

How can i keep the accuracy with out rounding

Nov 20 '05 #4
El Camino,

The general rule here is to use a standard base and always convert
from it. If a number comes in inches, then keep it in inches and do
the conversion at the last step to the required units.

If you start with 7 inches then want feet, it would be 7/12. To go
to yards, start over with 7/36. To go to Meters use 7*0.0254. This
will minimize the decimal error.
"El Camino" <an*******@disc ussions.microso ft.com> schrieb
Howdy all

Im trying to do a fairly accurate metric conversion
between:

inches
feet
yards

Im pretty sure that i have the right number for conversion
between length type.

Nov 20 '05 #5
Cor
Hi Armin,

Conversion of this kind of values will in general always stay a problem it
never will be posible to convert it 100% exactly and reconverting it again
although you can make the difference very small of course.

That has always been even before the computer did exist.

Just a thought

Cor
Nov 20 '05 #6
"Cor" <no*@non.com> schrieb

Conversion of this kind of values will in general always stay a
problem it never will be posible to convert it 100% exactly and
reconverting it again although you can make the difference very small
of course.
Hmmm...did I write something different? Or did you just want to add the
following sentence?
That has always been even before the computer did exist.

Just a thought


--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #7
Cor
>
Hmmm...did I write something different? Or did you just want to add the
following sentence?
That has always been even before the computer did exist.

Yes
Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

52
9678
by: piaseckiac | last post by:
I am producing a website on air and need a link to change the entire website from standard to metric for temperature, pressure, miles-kilometers, and volume. Thank you.
23
3954
by: Brian | last post by:
Despite charset being discussed to death, and despite having followed all of those threads, I still have problems. http://www.tsmchughs.com/recipes/soda-bread This page uses iso-8859-1 charset. From the headers: Content-Type: text/html; charset=iso-8859-1 Under ingredients are characters for fractions (188, 189, and 190) and the degree character (176), characters which Lynx can display on
8
2334
by: Rainer Queck | last post by:
Hi NG, in a dataset.datatable I have rows, containing metric data as doubles. I need to display/edit these values in textboxes depending on the culture (Metric/Inch). Is there something like a built in conversion functionality for that in the framework / visualstudio or do I have to do these conversions manually? Thanks for help and hints Rainer
3
3895
by: socondc22 | last post by:
Im stuck at this point. The way i was trying to do this was running if statement around my void function and then a else if statement around a different void function but it didnt work... right now i deleted part of what i had but left my skeleton of it there... #include <iostream> using namespace std; void get_numbers(double& input1, double& input2); void show_results(double output1, double output2); int main() { char letter;
2
1294
by: cbmeeks | last post by:
Man, I realize I've been asking a lot of questions lately. I appreciate you guys helping me in my thought process. This time, I have a design question I want opinions on. I'm building a business framework for tracking trending data. I have a class like: class Metric
0
9704
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
9569
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,...
0
10558
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10318
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10302
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
9130
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
5503
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2975
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.