Help Convert decimal to fraction
Need covert decimal de piont float to fraction
thats no easy for me.
you like help me with my probleam
I thank you very much
sorry for me English
i don't stand English
My e-mail is [email protected]
"jeans_mac" <[email protected]> wrote in
message
news:ecdb7a$k39$[email protected]..
> Need covert decimal de piont float to fraction
> thats no easy for me.
> you like help me with my probleam
> I thank you very much
>
> sorry for me English
> i don't stand English
http://www.lookmumimontheinternet.com/blog/?p=31
Similar Messages
-
C++, issues with converting a decimal to fraction
Hi all,
I am working on a C++ program that converts a decimal to a fraction, finds the lowest common multiple, multiplies the numerator by the denominator, then reduces the fraction again so the fraction will be 'numerator/1'.
I am using this code in a larger program to change a floating point slope value to a whole value for slope-intercept equations and standard form equations.
The program will run but I tested almost 500 numbers and 20 numbers made the program crash (it stalled and did not finish the equation, I had to close the terminal and open it up again... )
These 20 numbers I had problems with:
2.36, 7.36, 1.11, 1.001, 1.66, 1.88, 2.22, 2.13, 3.24, 3,26, 3.32, 3.43, 3.49, 3.51, 3.57, 3.68, 3.74, 3.76, 3.82
(I am sure there are more...)
I have tried c-style casting and dynamic and static casting to try to resolve this issue. Can someone help me out and point out why these certain numbers make the program crash and offer a possible sloution?
I tried debugging this program on gdb and keep on getting this frustrating message..
(gdb) break 16
No line 16 in file "init.c".
(gdb)
Here is the program's code:
//example.cc
#include <iostream>
#include "reduce.h"
#include "decimal-to-fraction.h"
using namespace std;
int main()
double deci;
double n, d;
while(1) {
cout << "Enter a decimal to convert to a fraction ('0' to quit): ";
cin >> deci;
cin.ignore(INT_MAX, '\n');
if(!deci) exit(0);
dec_to_frac(deci, n, d);
if (n * d != n){
cout << '\n' << deci << " = " << n << '/' << d << "\n\n";
cout<<'\n' << d << " x " << n;
n = d * n;
cout<< " = " << n << "\n\n";
cout<<'\n' << n << '/' << d;
reduce(n, d);
cout << " = " << n << '/' << d << "\n\n";
cout<<'\n' << n << "\n\n";
else
cout<<'\n' << deci<< "\n\n";
return 0;
#ifndef _REDUCE_H_
#error You must include "reduce.h" before this file
#endif /* def _REDUCE_H_ */
#ifndef _DECIMAL_TO_FRACTION_H_
#define _DECIMAL_TO_FRACTION_H_
void dec_to_frac(double decimal, double &numerator, double &denominator)
//numerator = static_cast<int >(decimal);
//numerator = (int )decimal;
numerator = decimal;
denominator = 1;
while(numerator != (int)numerator) {
numerator *= 10;
denominator *= 10;
reduce(numerator, denominator);
#endif /* def _DECIMAL_TO_FRACTION_H_ */
#ifndef _REDUCE_H_
#define _REDUCE_H_
void reduce(double &numer, double &denom)
int i;
for(i=2; i<=numer; ++i) {
if( ((numer/i) == ((int )(numer/i))) && ((denom/i) == ((int)(denom/i))) ) {
numer /= i;
denom /= i;
--i;
#endif /* def _REDUCE_H_ */Okay, a few things ('cause I'm picky too): LCM == "least common multiple" or "lowest common multiple", it's really interchangable. LCD == lowest common denominator, which is when you're adding two fractions and want to find the lowest denom. Now that we have that out of the way...
Using ++i or i++ as the third expression in your for loop will make zero difference.
for (int i=2; i<=numer; ++i)
will have exactly the same effect as
for (int i=2; i<=numer; i++)
, though they may have slightly different performances. The reason for this is that the third expression (i++ or ++i) is evaluated after every iteration of the loop, meaning it doesn't happen until the end of the loop body is reached, and then it's evaluated independently, meaning all you end up with is 'i' incrementing.
As for this:
if( ((numer/i) == ((int )(numer/i))) && ((denom/i) == ((int)(denom/i))) ) {
becomes
if (numer % i == denom % i == 0) {
That's about right, it would look more like
if (numer %i == 0 && denom % i == 0)
- the other way would probably not behave the way you expect.
Some other tips:
numer and denom should be 'int' or 'long' - not double. You don't expect your numerator and denominator to have decimal points, so use integral types - using floating point 'double's is likely what's getting you into this trouble -- floating point arithmetic is inherently imprecise. You might have better luck parsing the input yourself and constructing the numerator from that instead of reading directly into a floating-point number.
I'm hacking around with your code right now for fun; I'll let you know if I find anything.
==edit==
Oh, something else I wanted to mention; to break on a line in gdb you type:
break filename:linenumber
ie.
break example.cc:16
Last edited by Cerebral (2007-06-03 02:43:42) -
Conversion of book dimension from decimal to fraction
Hi,
I am a crystal report developer and new to SAP R3 environment. I am creating reports with SAP BW queries as source. I am working for a publishing client. They are storing the material (Book) details in the SAP system (Material table). SAP has a provision to capture physical properties of the book like width, height and thickness. They are entering details upto 3 decimal places precision in inches or in specified unit of measure.
When some extracts are generated from SAP System the values like 10.380 is converted as 10-3/8. But the actual 10-3/8 value is 10.375. The rounding is not uniform when I checked with few other values. I came to know from SAP experts these conversion are happened in an IDOC. I don't know much about this.
Can anyone help me in this conversion logic. Since I have to implement the same in my Crystal report. My BW query is just giving it in the decimals, my users are interested in seeing it as fraction since the other exports from SAP is showing it in fraction.
Thanks and Regards,
Subbu S.In the user exit of Outbound Idoc, they might have used some custom logic to implement the given logic.
It may vary on other factors as well. In your case, that should be verified or cross checked in your system only.
For converting the decimal to fraction in SAP, you can refer the below function module.
'CONVERT_TO_FRACTION' -
How to convert decimal notation to comma notation
Hi Folks,
I have an issue in converting decimal notation to comma notation for France.
I have changed the decimal notation in SU01 from 123.4 to 123,4 but when i run some custom program written by me it is extracting output as 123.4 than 123,4.
So i want to have the output of report to conver all numerical values(from decimal format to comma format) i.e., 123,4 format from the 123.4 format.
Please help me in fixing this issue
Edited by: Nishanth Kumar Reddy Chenchu on Apr 24, 2008 1:16 PMHi Nishant,
U can use the statement WRITE TO. This will write the data as per the user settings. When ever user changes his settings like decimal notations then this statement will write the data as per the current settings of the user.
DATA: l_amount1 TYPE wrbtr VALUE '123.45',
l_amount(16) TYPE c.
WRITE:/1 l_amount1.
WRITE l_amount1 TO l_amount.
WRITE:/1 l_amount.
Just copy paste above code in a sample program. First execute this program and note the output. Then change the user settings for decimal notations and log of from SAP(Because user settings will become active only after fresh login). Now execute ur report and see the difference. In this way u no need to change the program when ever user changes his settings.
This thing not pnly applies for amount but also for date, time Quantity fields
Thanks,
Vinod -
How to convert decimal numbers to Hours and minutes
Hi,
I am using SSRS 2005. I want to convert decimal numbers to Hours and minutes.
Say suppose, I am adding daily work hours and minutes and the total is 208.63.
Here 208 hrs and 63 minutes. How to convert this to 209 hrs 03 minutes in SSRS.
Any In-built function is there? or how to do using custom code?
Appreciate your help.
Regards,
Balasuppose if field name is TotalDailyHours you can do it as below
=CStr(Cint(Floor(val(Fields!TotalDailyHours.Value)) + ((val(Fields!TotalDailyHours.Value)-Floor(val(Fields!TotalDailyHours.Value)))*100)/60)) + ":" +
Right("00" +Cstr(Cint(((val(Fields!TotalDailyHours.Value)-Floor(val(Fields!TotalDailyHours.Value)))*100) Mod 60)),2)
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Help converting pdf forms to a word document
Debbie
I need help converting a pdf form to a word document.I just purchase adobe to be able to convert a pdf form into a word document but it is not working..
-
Help convert LV5.1vi to 8.x please.
Can someone help convert the vi at the link below to a contemporary version of LV?
http://zone.ni.com/devzone/cda/epd/p/id/558
I don't have anything old enough installed to open it. I don't even know what it is, but one of my users requested it.
Thanks in advance!
Chris
Solved!
Go to Solution.Here it is in 8.2, though once you see it, I think you will find it would be easier to just use Read From Spreadsheet File.
Attachments:
parse_lookup_table.vi 23 KB -
hi help convert date
April 26, 1904....August 12, 1979
to dd/mm/yyyySELECT CONVERT(VARCHAR(15),CAST('April 26, 1904' AS DATE),103)
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
Download helper converts to .flv instead of .avi
since a few months when downloading a video from the same source, the download helper converts to .flv and no longer to.avi.
what do I need to do to have .avi?
Even if it downloads as .avi, it converts automatically to .flv .
Thank you for help.
Rgds piaThe first thing that you need to consider is whether or not
this project
will work well on the web. If you have to make a bunch of
compromises to
get it working on the web, then it may not represent you
well.
That said, you can use FLVs in Director MX 2004 with the
latest updates.
However, you can't stream the FLVs, you have to encapsulate
each one in
an SWF and then use the SWF. So if its the streaming that
you're after,
you may want to use QT instead. You can stream that.
Regardless of the video media that you use, you need to be
sure that you
aren't taking a smooth CD based experience and turning it
into a click
and wait, click and wait, less than elegant web experience.
If you want
to showcase your video capabilities then you may want to
build a web
specific tool. Or, you may want to let site visitors request
a CD to be
mailed to them.
Rob
Rob Dillon
Adobe Community Expert
http://www.ddg-designs.com
412-243-9119
http://www.macromedia.com/software/trial/ -
Hi I would like to know if you can convert decimal to binary using actionscript 3.0?
Hi I would like to know if you can convert decimal to binary using actionscript 3.0?
Hi thanks for the response Ive tried to implement the code as you stated but it is not outputting please if you could check the following code and let me know where Ive gone wrong that would be much appreciated Thanks!.
miles_txt.addEventListener(KeyboardEvent.KEY_DOWN,convertKilometres);
miles_txt.restrict ="0-9";
function convertKilometres (k:KeyboardEvent):void {
var miles:Number;
var kilometres:Number;
if (k.keyCode == Keyboard.ENTER){
miles=Number(miles_txt.text);
kilometres=miles* 1.609344;
kilometres_txt.text = kilometres.toPrecision(2);
kilometreConvert_txt.addEventListener(KeyboardEvent.KEY_DOWN,convertKiloToMile);
kilometreConvert_txt.restrict = "0-9";
function convertKiloToMile(k:KeyboardEvent):void{
var kilometreConvert:Number;
var milesAnswer:Number;
if (k.keyCode==Keyboard.ENTER) {
kilometreConvert=Number(kilometreConvert_txt.text);
milesAnswer=kilometreConvert* 0.621371192;
milesAnswer_txt.text = milesAnswer.toPrecision(2);
binary_txt.addEventListener(KeyboardEvent.KEY_DOWN, checkEnterKey2);
function checkEnterKey2(e:KeyboardEvent):void{
if(binary_txt.text != '' && e.keyCode == Keyboard.ENTER){
decimal_txt.text=binaryToDecimal(binary_txt.text).toString();
function binaryToDecimal(s:String):Number{
var n:Number = 0
for(var i:int=0;i<s.length;i++){
n+=Number(s.substr(i,1))<<(s.length-1-i)
return n;
function decimalToBinary(n:Number):String{
return n.toString(2);
return_btn.addEventListener(MouseEvent.CLICK, goBackToCalculator);
function goBackToCalculator(e:Event):void
mybuttonSound.play();
gotoAndStop("Calculator");
clear_btn.addEventListener(MouseEvent.CLICK,clearField);
function clearField(e:MouseEvent):void{
mybuttonSound.play();
miles_txt.text ="";
kilometres_txt.text ="";
milesAnswer_txt.text ="";
kilometreConvert_txt.text ="";
binary_txt.text ="";
decimal_txt.text =""; -
Nesting CONVERT(DECIMAL)
SUM(CONVERT(DECIMAL(12,2),CONVERT(DECIMAL(12,2),DATEDIFF(mi,StartTime,FinishTime))/60) - ISNULL(Breaks,0))
From the query above, I had to nest Convert decimal twice before getting the result. What is the logic behind this sort of query? I got the result I wanted but I want to equally know the reason for having decimals repeated the way I just did.
Thank you.
ZionliteHi Yookos/Zionlite, It looks like Himanshu explained as shown below, the third one. Am not getting what you are trying..Please eloborate.
>>>SELECT
CONVERT(DECIMAL(12,2),DATEDIFF(mi,GETDATE()-3,GETDATE()))
-- 4320.00
SELECT
CONVERT(DECIMAL(12,2),DATEDIFF(mi,GETDATE()-3,GETDATE()))
/60
--72.000000
SELECT
CONVERT(DECIMAL(12,2),CONVERT(DECIMAL(12,2),DATEDIFF(mi,GETDATE()-3,GETDATE()))
/60)
--72.00 -
Need help converting from 4.0 to 2011
hello,
Need help converting files from 4.0 to 2011.
thank you
Solved!
Go to Solution.
Attachments:
noise source.vi 73 KB
8673D.vi 30 KB
8970 FREQ.vi 26 KBattached as 8.2, which you can open
missing some subVIs - not sure if you already have them
Attachments:
8673D.vi 13 KB
8970 FREQ.vi 11 KB
noise source.vi 24 KB -
Need help converting Client-Server to JSP
Hi;
I have a purely data driven, dynamic, meta driven program
in Java 1.4. Runs on almost any SQL database, and the
systems analysts can do most of the programming just by
entering the data. All screens and sql are auto-genned
at runtime.
I was wondering if there was anyone interested in helping
convert to JSP. I would be willing to give part of the
company profits. It is better then me asking a million
questions here, although there are lots of great experts here.
-Trent
Thanks.My personal email address is [email protected] I would love to contact you if you drop me your phone number.
Manohar -
Hi all,
How to convert decimal type length 3(e.g:25.0) to char type.......
Thanks in advancehi,
data : var_dec type p decimals 3,
var_char(10).
<b>move var_dec to var_char.</b>
else use FM
CALL FUNCTION <b>'CEVA_CONVERT_FLOAT_TO_CHAR'</b>
EXPORTING
FLOAT_IMP = P_ORIGEN
FORMAT_IMP = CAMPO_FLOAT
IMPORTING
CHAR_EXP = C_DESTINO.
Regards,
Santosh -
Need help converting a PDF to excel
Need help converting a PDF to excel, the icon to convert dissappeared suggestions?
Open the file in Acrobat, use File --> Save As... --> Microsoft Word.
Mylenium
Maybe you are looking for
-
Can't get SQL 2008 Express installed
Hope some one can help me. I am trying to install 2008 Express version and I constantly get the following error. I have tried pretty much all flavors of express and get the same thing. I uninstalled several time and reinstall but keep getting the sam
-
Authorization object in program
Hi All, I have a requirement to determine the sales areas that a business partner is authorized to edit in my report program. Can this be done by programatically using the Authorization object CRM_BP_SA. Thanks, Shilpi
-
Hi All, Hopefully this is in the right place and someone can offer some assistance for me. I will try to lay this out correctly (newbie on this forum). Have installed WDS on Server 2012 R2. Settings altered... Setup my server as standard, nothing spe
-
I need to de-authorize older macbook and ipods. I read support for Itunes via my account. Directions to "manage devices", but only choice is to deauthorize all computers. How can I get list of all devices? My account says four devices are alread au
-
Help with Rules to Copy all Sent and Received Mail
Friends: 1. I have created a rule to copy all sent mail to a folder as follows: mail>prefs>rules>add rule>description:All Sent Mail>To Contains @>Coppy Message to All Sent Mail folder Is there a better way to do this? 2. Similarly I tried the above f