Percentage Plus and Minus [closed] - sql

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
Having an issue calculating money after percentages have been added and then subtracting , I know that 5353.29 + 18% = 6316.88 which I need to do in my tsql but I also need to do the reverse and take 18% from 6316.88 to get back to 5353.29 all in tsql, I might have just been looking at this too long but I just cant get the figures to calculate properly, any help please?

newVal = 5353.29(1 + .18)
origVal = newVal/(1 + .18)

6316.88 is 118%, so to get back you need to divide 6316.88 by 118, then multiply by 100.
(6316.88/118)*100=5353.29

To Add n% to X
Result = X * ( 1 + (n / 100.0))
To do the reverse
X = Result / ( 1 + (n / 100.0))

Related

Haven´t found how to convert a num to a float [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
i am trying to convert a num toFloat but i dont find anything useful at the moment,
Does anyone know how to do it?
I am using this to obtain the number in the string but i don´t find how to convert it to float
val str = "awdafafaf123asfasf"
val num = str.replace(Regex("[^0-9]"),"")
println(num)
}
You can use String.to*() category of functions to convert a string to various other data types.For example:
val str = "awdafafaf123asfasf"
val num = str.replace(Regex("[^0-9]"),"")
val intValue: Int = num.toInt()
val doubleValue: Double = num.toDouble()
val floatValue: Float = num.toFloat()
println(num)
Kotlin standard library also provides String.to*OrNull() versions of these functions which return null if conversion is not possible.

Get all possible combination from a value [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
how can i make a calculation to say the sum of certain 4 numbers to give a certain result like 280.
all possible combinations of numbers from 1 to 80. display all the combinations of 4 numbers that have the sum I set in the textbox. I should find out the easiest way to do this, and I would be grateful if you could help me. there should be no repetitions in a instance, like 60 60, 80 80. thus eliminating the unimportant variants, and the important ones will remain.
Textbox1.Text
68,69,70,72 = 280
67,69,70,74 = 280
66,69,70,75 = 280
65,69,70,76 = 280
64,69,70,77 = 280
and so on...
I would need a model, how could I conceive such an algorithm? Thank you very much.
Get all combinations which declares a sum from a certain number
There may be a very large number of such numbers. Therefore I'm going to first get a concise data structure that describes it, then run code that executes on every one.
Since I don't have vb.net I will do it in Python. Hopefully the translation is not too hard. I have used closures and dictionaries. I did not use the natural Pythonic iterators.
#! /usr/bin/env python3
def find_combs_data (count, target, upper):
# First we create a cache of known answers.
cached = {}
def find_combs (count_left, target_left, lower):
cache_key = (count_left, target_left, lower)
# Only do the calculation when needed.
if cache_key not in cached:
# Base case and sanity check.
if count_left == 0:
if target_left == 0:
return []
else:
return None
elif upper * count_left < target_left:
return None
elif target_left < lower * count_left:
return None
answer = {}
for i in range(lower, upper + 1):
result = find_combs(count_left - 1, target_left - i, i + 1)
if result is not None:
answer[i] = result
if len(answer):
cached[cache_key] = answer
else:
cached[cache_key] = None
return cached[cache_key]
final = find_combs(count, target, 1)
return final
def execute_on_combs (fn, count, target, upper):
passed = []
def execute_on_data (d):
if d == []:
fn(passed)
else:
for i, d_inner in d.iteritems():
passed.append(i)
execute_on_data(d_inner)
passed.pop()
execute_on_data(find_combs_data(count, target, upper))
def show (x):
print(x)
execute_on_combs(show, 4, 270, 80)

Type conversion to double value in java [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
public class TypeConversion4 {
public static void main(String[] args) {
double d = 2D + 2d + 2. + 2l + 2L + 2f + 2F + 2.f + 2.D;
System.out.println(d); //prints 18.0
}
}
how it prints 18.0. Can anyone provide some analysis.
So, what's the problem? All these twos converted to the biggest type while summing up and then the result casted to double. But you can store 2 in long, int, double and float without any error. That means that all you have to do is to sum these 9 twos and come up with 18.0.

How do I set x = x + 1 for y amount of times without a for or do loop? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
In Vb I am trying to set variable x = x + 10 for y amounts of time.
What I have now is this:
For z As Double = 0 To Y
x = x + 1
Next
I want no do or for loops because they take up a lot of time and resources for larger y values.
This is a job for (cue dramatic music) Mathman!
I think you'll find multiplication is the key, something along the lines of
x = x + y * 10
if you want to add ten each time, or the even simpler
x = x + y
if you're only adding one.
Although you may have to use (y + 1) instead of y if your loop truly is 0 through y inclusive. It's a little unclear from the question exactly what you're after.

Basic Gauss Elimination yields wrong result? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I was reading a book and got stuck at a particular point. I stuck here in the following and want to know that how x+(y+z)=0.0 calculated ?
Further in the following example of Gauss elimination method I couldn't get how 2.5/(-0.005)=-2500 got calculated? From where they took this "-0.005" value .
Computers do not do arithmetic in the same way that people do on pen and paper. Numbers have limited precision. Imagine you had a number system where you could only have 4 digits after the decimal point and also a factor of 10 to some power, and so numbers looked like:
±0._ _ _ _ × 10ⁿ
Now, add these two numbers:
0.1234 × 10⁸
0.5678 × 10⁰
You are adding
12340000
and
00000000.5678
The real sum is
12340000.5678,
but the theoretical computer here can store only the first four digits, giving
12340000 = 0.1234 × 10⁸
That is why y+z in the textbook problem is equal to y, and x + (y + z) = 0 ≠ (x + y) + z.
x = 0.1 × 10¹⁰
y = -0.1 × 10¹⁰
z = 0.1 × 10¹
x + y = 0.0
(x + y) + z = 0.0 + 0.1 × 10¹ = 0.1 × 10¹
(Single-precision) floats have only 8 digits of precision in IEEE arithmetic. These correspond to the C float datatype. But y = - 10⁹ z, and z disappears when you add y and z. So,
y + z = -999999999 = -0.1 × 10¹⁰ after rounding.
x + ( y + z) = 0.0
The book also has a typographical error. The quotient should have been 2.5/(-0.001), from rows 2 and 3, column 2 of the matrix.
This is why computer algorithms for matrix algebra are tricky; they seek to minimize the effect of roundoff error and underflow. Unfortunately, any flaw in an algorithm can lead to very bad problems. One test is to look at the Hilbert matrix
H_n = (1/(i+j-1)) 1 ≤ i, j ≤ n
The inverse of this matrix is has integer entries, but that matrix and its inverse are spectacularly ill-conditioned. Any numerical error in computing the inverse will lead to wildly-wrong values. Twenty years ago, I tested the inverse routine for the then-current version of Matlab. It was acceptable for H_10, but too poor to use for H_12.