ROunding to nearest .125 or 1/8 of a yard in Acrobat professional - acrobat

I am trying to have a solution for a pdf figure out a equation and round up to the nearest 1/8th of a yard. The equation I am using that I want rounded is (Text17/15)+.25 How can I make that round up everytime?

Assuming that Text17 is a text field, containing a numeric value, and you always want to round up, you could put somehting like this into the Calculate event of the field which is supposed to show the result:
event.value = util.printf("%.3f", Math.ceil(((this.getField("Text17").value*1 / 15) + 0.25) * 8) / 8 );
And that should do it.

Related

How to write in vb.net a decimal number without rounding the 12 digits after the decimal point?

I try to write the result of the division of the number 5991 by 2987 in vb.net, without rounding the decimal or floating point, strictly equal to 2.005691329092 on 12 digits after the decimal point. The decimal part (0.05691329092) is also noted 17/2987 in scientific notation. My tests always led me to 2.005691329093 rounding!
2 17/2987
Actual value is correct, issue is how to format value to display it as expected.
There are no built-in method, but you can multiply value by required amount of digits after decimal point and truncate it.
Dim value As Double = 5991.0 / 2987.0
value = Math.Truncate(value * Math.Pow(10, 12)) / Math.Pow(10, 12)
Console.WriteLine($"Result: {value:F12}")

Round number after 0,1

As you know, number rounds bigger one after 0,5 , but I want that number rounds bigger one after 0.1 . Can I do it ?
Where I will use it is ;
I will take input from user and ı will copy them ten by ten other worksheet. For example, ıf the user input's is 11, then I have to open 2 sheets .
You could use the existing behavior of the ROUND() function by adding a value to it like:
ROUND(x + 0,4, 2) '2 decimal places, 0.4 added as a bias
In this way, if x were 5,1, you'd really be rounding 5,1 + 0,4 or 5,5, and then the normal behavior of the function would work for you. Adding a bias in this way lets you control rounding (up) behavior easily.

Converting height and inches (with decimal) to inches

I have a character based height field with some irregular entries. The most typical case is straightforward such as 6'3", or 5'11' (easy to convert). Unfortunately, we also have some entries with a decimal in the inches value such as 5'2.5" or 5'3.25".
My goal is to convert to an integer-based total inches, taking out the decimal, and rounding to the nearest inch.
Any helps?
First Get your feet (the number before the ') and multiply by 12, then get your inches (number between ' and ") ad round to the nearest whole number, add these numbers together and that's your height in inches :)
This query might help:
SELECT
CAST(SUBSTRING(your_column, 0, CHARINDEX ('''',your_column)) as INT)
* 12
+ ROUND(CAST(SUBSTRING(your_column,
CHARINDEX('''', your_column) + 1,
LEN(your_column) - CHARINDEX('''',your_column) - 1) as DECIMAL),0)
as Height

How do you multiply two fixed point numbers?

I am currently trying to figure out how to multiply two numbers in fixed point representation.
Say my number representation is as follows:
[SIGN][2^0].[2^-1][2^-2]..[2^-14]
In my case, the number 10.01000000000000 = -0.25.
How would I for example do 0.25x0.25 or -0.25x0.25 etc?
Hope you can help!
You should use 2's complement representation instead of a seperate sign bit. It's much easier to do maths on that, no special handling is required. The range is also improved because there's no wasted bit pattern for negative 0. To multiply, just do as normal fixed-point multiplication. The normal Q2.14 format will store value x/214 for the bit pattern of x, therefore if we have A and B then
So you just need to multiply A and B directly then divide the product by 214 to get the result back into the form x/214 like this
AxB = ((int32_t)A*B) >> 14;
A rounding step is needed to get the nearest value. You can find the way to do it in Q number format#Math operations. The simplest way to round to nearest is just add back the bit that was last shifted out (i.e. the first fractional bit) like this
AxB = (int32_t)A*B;
AxB = (AxB >> 14) + ((AxB >> 13) & 1);
You might also want to read these
Fixed-point arithmetic.
Emulated Fixed Point Division/Multiplication
Fixed point math in c#?
With 2 bits you can represent the integer range of [-2, 1]. So using Q2.14 format, -0.25 would be stored as 11.11000000000000. Using 1 sign bit you can only represent -1, 0, 1, and it makes calculations more complex because you need to split the sign bit then combine it back at the end.
Multiply into a larger sized variable, and then right shift by the number of bits of fixed point precision.
Here's a simple example in C:
int a = 0.25 * (1 << 16);
int b = -0.25 * (1 << 16);
int c = (a * b) >> 16;
printf("%.2f * %.2f = %.2f\n", a / 65536.0, b / 65536.0 , c / 65536.0);
You basically multiply everything by a constant to bring the fractional parts up into the integer range, then multiply the two factors, then (optionally) divide by one of the constants to return the product to the standard range for use in future calculations. It's like multiplying prices expressed in fractional dollars by 100 and then working in cents (i.e. $1.95 * 100 cents/dollar = 195 cents).
Be careful not to overflow the range of the variable you are multiplying into. Your constant might need to be smaller to avoid overflow, like using 1 << 8 instead of 1 << 16 in the example above.

programing ranging data

I have 2 inputs from 0-180 for x and y i need to add them together and stay in the range of 180 and 0 i am having some trouble since 90 is the mid point i cant seem to keep my data in that range im doing this in vb.net but i mainly need help with the logic
result = (x + y) / 2
Perhaps? At least that will stay in the 0-180 range. Are there any other constraints you're not telling us about, since right now this seems pretty obvious.
If you want to map the two values to the limited range in a linear fashion, just add them together and divide by two:
out = (in1 + in2) / 2
If you just want to limit the top end, add them together then use the minimimum of that and 180:
out = min (180, in1 + in2)
Are you wanting to find the average of the two or add them? If you're adding them, and you're dealing with angles which wrap around (which is what it sounds like) then, why not just add them and then modulo? Like this:
(in1 + in2) mod 180
Hopefully you're familiar with the modulo operator.