Jump to content

This topic is 7137 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

I have a problem reducing my fraction to there lowest denominator. the calculation I found returns 2/64 instead of 1/32. I found this cal from earlier postings and I am a novice. the user are setting up equipment with the script and results should be in 64th,32nd,16th,8th,1/4th, and 1/2th,I need the fractions to break down to their simplest forms.

Case(

GetAsNumber(Cut 1Adecimal)<.015625; "";

Mod(Cut 1Adecimal*2;1)<.015625; "1/2";

Mod(Cut 1Adecimal*4;1)<.015625; Round(Cut 1Adecimal*4;0) & "/4";

Mod(Cut 1Adecimal*8;1)<.015625; Round(Cut 1Adecimal*8;0) & "/8";

Mod(Cut 1Adecimal*16;1)<.015625; Round(Cut 1Adecimal*16;0) & "/16";

Mod(Cut 1Adecimal*32;1)<.015625; Round(Cut 1Adecimal*32;0) & "/32";

Round(Cut 1Adecimal*64;0) & "/64")

Posted

I can't see why your calculation goes wrong but it may be better to get rid of the extraneous extra bits right at the start. I am assuming from your calculation that the field Cut 1Adecimal has a value between 0 and 1. In the calculation which I have checked to some extent in v8 I have abbreviated the field to CAD (look out for semi-colons which I have not converted to commas)

Case(

Int(CAD*64) < 1,"",

Mod(Int(CAD*64),32) = 0, "1/2",

Mod(Int(CAD*64),16) = 0;Div(Int(CAD*64),16) & "/4",

Mod(Int(CAD*64),8) = 0, Div(Int(CAD*64);8) & "/8",

Mod(Int(CAD*64);4) = 0, Div(Int(CAD*64);4) & "/16",

Mod(Int(CAD*64),2) = 0, Div(Int(CAD*64),2) & "/32",

Int(CAD*64) & "/64")

This is effectively the same calculation but written in a slightly different format trying to use integer arithmetic. Note that it always goes down to the nearest appropriate fraction. For example, 0.3125 gives 1/32 and 0.3124 gives 1/64

This topic is 7137 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.