Hello all,
I have the following code:
float valueCalculated = (val1 / val2) * 100;
What I want to be able to do is to cap the maximum value of valueCalculated to 100.
I believe I could do this using some sort of if statement, but this would mean many more lines of code. Edit// This is not the case, see the answers below.
Thanks,
...
I want to calculate the average of a set of angles, which represents source bearing (0 to 360 deg) - (similar to wind-direction)
I know it has been discussed before (several times). The accepted answer was Compute unit vectors from the angles and take the angle of their average.
However this answer defines the average in a non intuitiv...
Hi,
I'm experiencing a strange error in IE on this site: http://www.davenuttall.co.uk
The fund-raising barometer on the left-hand side animates upwards to the correct position just fine in all other browsers, but throws an 'invalid argument' error in IE.
I think it's caused by the easing method - easeOutElastic - from the easing plugi...
Ok, I'm not sure if the title is that effective but its the best I could come up with.
Basically here is the scenario.
I have 11 categories. In each category, I have items, but one category might have 1 item, 1 might have 20.
Now i want to separate the 11 categories into 5 stacks or columns.
I want each of the stacks to contain an eq...
I've written an iPhone App that calculates a total cost by adding/subtracting units of predetermined cost. This was working fine until I realised that the float values I was using caused the total to be inaccurate so I started to look into using NSDecimalNumber. I'm now rather confused and have an 'out of scope' error. Relevant sections ...
So, I am trying to calculate the time between two dates that fits certain criteria (here: work / non-work) and I'm confused about the results as I can't find out why it's wrong.
But first, some code;
**Input Date A:** 2009-01-01 2:00 pm
**Input Date B:** 2009-01-02 9:00 am
So, as you can see, the total timespan (calculated e.g. by Da...
Is there a way/tool/technique to calculate the processor and memory cost of a specific MySQL query?
...
We're writing a very simple program to execute on a processor we've built for a class. It doesn't have the capability to multiply or divide. We do however, had support for addition, subtraction, and, or, and branching for loop control (like branch on equal if you are familiar with MIPS). We were thinking a neat program to run on it would...
Hi - I'm building a basic app to track progress of projects through db. When the project is first created, it saves the created_at timestamp (yes, it's rails), and the user can then update the following fields:
status (choose from 'in progress', 'frozen', 'done' or 'scratched')
priority ('none', 'minor', 'major')
days (the estimate, in...
I have a weird problem in asp.NET when calculating how many hours we need to invoice.
In the below example, we have a total of 75,9 hours that need to be invoiced.
These hours are spread over several database rows (TimeIDs).
Basically, I always deduct the "amount_invoiced" from the "to invoice" hourly count:
TimeID:25433 - to invoice...
I have a situation where I have a couple of variables who's values depend on each other like this:
A is a function of B and C
B is a function of A and C
C is a function of A and B
Either value can change on the UI. I'm doing the calculation and change notification like this:
private string _valA;
private string _valB;
private string _...
how to find difference between two dates
...
I am using a mySQL database on a site to calculate the distance of multiple points based on zipcodes, latitudes and longitudes.
E.g. Point A at zip code 123456 has latitude 100 and longitude 200
Using a static formula, the distance between Point A and multiple other points are calculated and returned real time. The reference Point A may ...
Hi All
i want to calculate the NPV ( Net Present Value ) using PHP.
Below is the detail which i have.
discount rate : 15%
Cash Flow Values per Year:
Year 1: 110000
Year 2: 122000
Year 3: 135200
Year 4: 149720
Year 5: 157706
Year 6: 166091
NPV Formula which i am using.
NPV = sum of all years( (Ci...
I am carrying out a number of calculations using NSDecimal and am creating each NSDecimal struct using the following technique:
[[NSNumber numberWithFloat:kFloatConstant] decimalValue]
I am using NSDecimal to avoid using autoreleased NSDecimalNumber objects (if the NSDecimalNumber approach to accurate calculations is used). However it...
I basically have a few variables
0 < na < 250
0 < max <= 16
nb = (na + max - 1) / max
n has the following characterstics
0 <= i < nb - 1 => n = max
i = nb - 1 => n = na - i * max
Is there an easy way to do this without the ternary operator?
for (i = 0; i<nb;i++) {
n = ((i + 1) * max > na ? na - (i * max) : max);
}
Examples...
I tend to use math functions of constant expressions for convinience and coherence (i.e log(x)/log(2) instead of log(x)/0.3...). Since these functions aren't actually a part of the language itself, neither are they defined in math.h (only declared), will the constant ones get precalculated at compile time, or will they be wastefully calc...
My problem is not usual. Let's imagine few billions of strings. Strings are usually less then 15 characters. In this list I need to find out the number of the unique elements.
First of all, what object should I use? You shouldn't forget if I add a new element I have to check if it is already existing in the list. It is not a problem in ...
Hi
I get some GPS coordinates from Google Maps and I need to find the distance between them
using Objective C. I have implemented the formula but I get results that are way to big.
I have tested the values from Google Maps by passing them back into Google Earth and a Geocoding service on the internet and everything checks out. Im now b...
I'm using JQuery Calculation plugin with the following script:
function recalc() {
jQuery("input[class^=percent]").calc(
"(invoice - cost)/invoice * 100",
{
invoice: jQuery("input[class^=invoice]"),
cost: jQuery("input[class^=cost]")
},
function...