multiplication

JavaScript simple calculation

馋奶兔 提交于 2020-01-11 13:32:27
问题 I'm pretty sure I'm being stupid but why isn't this working!? form.find( '.per_time' ).on( 'change', function() { var price = parseInt( form.find( '.section-price' ).attr('data-price'), 10 ) ; var multiplier = parseInt( $( this ).val(), 10 ); var newprice = (price / 7) * multiplier; form.find( '.section-price .price' ).html( newprice ) }) It's this line I'm concerned about: var newprice = (price / 7) * multiplier; The calculation is not dividing by 7, it only calculates price * multiplier ?

JavaScript simple calculation

◇◆丶佛笑我妖孽 提交于 2020-01-11 13:32:11
问题 I'm pretty sure I'm being stupid but why isn't this working!? form.find( '.per_time' ).on( 'change', function() { var price = parseInt( form.find( '.section-price' ).attr('data-price'), 10 ) ; var multiplier = parseInt( $( this ).val(), 10 ); var newprice = (price / 7) * multiplier; form.find( '.section-price .price' ).html( newprice ) }) It's this line I'm concerned about: var newprice = (price / 7) * multiplier; The calculation is not dividing by 7, it only calculates price * multiplier ?

Exact decimal arithmetic in Julia

浪尽此生 提交于 2020-01-11 04:55:08
问题 Due to the nature of floating-point math, .4 * .4 = 0.16000000000000003 in Julia. I want to get the mathematically correct answer of 0.16 , in a CPU-efficient way. I know round() works, but that requires prior knowledge of the number of decimal places the answer occupies, so it isn't a general solution. 回答1: Some options: Use the inbuilt Rational type. The most accurate and fastest way would be 16//100 * 16//100 If you're using very big numbers these might overflow, in which case you can use

how to calculate (a times b) divided by c only using 32-bit integer types even if a times b would not fit such a type

别说谁变了你拦得住时间么 提交于 2020-01-11 03:15:08
问题 Consider the following as a reference implementation: /* calculates (a * b) / c */ uint32_t muldiv(uint32_t a, uint32_t b, uint32_t c) { uint64_t x = a; x = x * b; x = x / c; return x; } I am interested in an implementation (in C or pseudocode) that does not require a 64-bit integer type. I started sketching an implementation that outlines like this: /* calculates (a * b) / c */ uint32_t muldiv(uint32_t a, uint32_t b, uint32_t c) { uint32_t d1, d2, d1d2; d1 = (1 << 10); d2 = (1 << 10); d1d2 =

Perfoming Cartesian product on arrays

泪湿孤枕 提交于 2020-01-10 04:11:32
问题 I'm interested in performing a Cartesian product on n arrays. I can write the code if I know the number of arrays ahead of time. For example, given 2 arrays: int[] a = new int[]{1,2,3}; int[] b = new int[]{1,2,3}; for(int i=0; i<=a.length; i++){ for(int j=0; j<=b.length; j++){ System.out.println(a[i]*b[j]); } } The problem is that at runtime, I do not know the number of arrays. I may have 2 arrays, or I may have 100 arrays. Is there a way that I can do this? Thanks! 回答1: One way to approach

Python - Multiplying an element from 2D list

会有一股神秘感。 提交于 2020-01-05 05:40:13
问题 I would like to multiply one of the elements from the 2D list by an integer. However, once I execute the code I get the following: I was expecting the outcome to be just a tuple, rather than a list, and would like for it to be a tuple rather than a list. [3, 3, 3] [6, 6, 3, 3, 3, 3] This is my code: list = [[0.5],[0.3],[0.1]] def funcOne(juv): newAd = juv * list[0] return newAd def funcTwo(ad,sen): newSen = (ad* list[1]) + (sen* list[2]) return newSen print(funcOne(3)) print(funcTwo(2,4)) My

Multiplication using Logical shifts in MIPS assembly

早过忘川 提交于 2020-01-02 18:03:38
问题 Can someone please give me pointers on how I can go about making a code that multiplies using shifts in MIPS assembly? I don't understand how having a number 2^n can help me multiply using an odd multiplicand I currently have this code, I'm trying to make a calculator .text li $v0, 4 la $a0, ask_1 syscall li $v0,5 syscall move $s1, $v0 li $v0, 4 la $a0, ask_2 syscall li $v0,5 syscall move $s2, $v0 #sll $s2, $s2, 3 #$s2 * $s2^3 = result srl $s2, $s2, 1 li $v0, 1 la $a0, ($s2) syscall .data ask

How to calculate EditText value in Android?

孤街醉人 提交于 2020-01-01 19:18:09
问题 In an Android app, I'm using two EditText controls and multiplying their two values. If one EditText is null and in the second one I put a value, it's not working properly. How can I deal with this case, in which I have a value in one EditText and a null in the other and I want to multiply the two values? 回答1: First of all, you need to have a trigger for when to perform the calculation. Say it's a button, or, even better, every time the value of one of your EditText s changes: private

Ruby - Multiplication issue

不想你离开。 提交于 2020-01-01 12:27:10
问题 My output is like this - ruby-1.9.2-p290 :011 > 2.32 * 3 => 6.959999999999999 And I remember sometime back on another machine I had got it like.. 2.32 * 3 = 6 What is my mistake? Thanks a ton for reading this. :) 回答1: If you really want to round down to an integer then just (3 * 2.32).to_i but I think that's unlikely. Usually you just want to format the slightly imprecise floating point number to something like this "%0.2f" % (3 * 2.32) => "6.96" If you really want to work with the exact

Opencv multiply scalar and matrix

戏子无情 提交于 2020-01-01 07:59:47
问题 I have been trying to achieve something which should pretty trivial and is trivial in Matlab . I want to simply achieve something such as: cv::Mat sample = [4 5 6; 4 2 5; 1 4 2]; sample = 5*sample; After which sample should just be: [20 24 30; 20 10 25; 5 20 10] I have tried scaleAdd , Mul , Multiply and neither allow a scalar multiplier and require a matrix of the same "size and type". In this scenario I could create a Matrix of Ones and then use the scale parameter but that seems so very