Why, when subtract a decimal number in system out the output not correct [duplicate] - output

This question already has answers here:
Is floating point math broken?
(31 answers)
Closed 6 years ago.
why when i print this code in print statement the output will be not correct.
System.out.println(3.15 - 3);
the output is:
0.1499999999999999
i think the output must be.
0.15

System.out.println((float)(3.15 - 3.0)); //the answer is 0.15
System.out.println(3.15f - 3); //the answer is 0.1500001
System.out.println(3.15 - 3.0); //the answer is 0.1499999999999999

Related

why is ceil used here and what purpose does it serve [duplicate]

This question already has an answer here:
Practice computing grid size for CUDA
(1 answer)
Closed 3 years ago.
I was looking at a game of life gpu code and could not understand why is ceil used for
dim3 cpyBlockSize(BLOCK_SIZE,1,1);
dim3cpysimulationRowssimulationSize((int) ceil (size/(float) cpyBlockSize.x), 1, 1);
dim3 cpysimulationColssimulationSize((int) ceil ((size+2) / (float) cpyBlockSize.x), 1, 1);
Hard to tell without much context but this is my best guess:
Integer division rounds down but it appears the required behavior is to have (size/(float) cpyBlockSize.x) rounded up. So they cast cpyBlockSize.x to a float so the result of the division is a decimal, then rounded that decimal up using ceil to achieve the expected behavior.
For example in most* programming languages (C included):
> print (5/2)
> 2
> print (5/(float)2)
> 2.5
> print (ceil(5/(float)2))
> 3

Call two functions in one click [duplicate]

This question already has answers here:
Two onClick actions one button
(4 answers)
Closed 5 years ago.
Is it possible to call two functions in one click in html?
Here is my code:
<div class="user-list"
(click)="threadService.createChatWindow()"
(click)="matrixService.newRoom(thread)">
</div>
It does not work
You cannot have two attributes, instead combine with ;:
<div class="user-list"
(click)="threadService.createChatWindow(); matrixService.newRoom(thread)">
</div>

Report with combined fields

I need to create report to render like image below:
So, for each question, I have several answers (4 or 5 answers), and every question have belonging image.
DATASET:
QuestionId QuestionName Image AnswerId AnswerText
1 Question 1 Image 1 Answer 11
1 Question 1 Image 1 Answer 12
1 Question 1 Image 1 Answer 13
1 Question 2 Image 1 Answer 21
1 Question 2 Image 1 Answer 22
1 Question 2 Image 1 Answer 23
1 Question 3 Image 1 Answer 31
1 Question 3 Image 1 Answer 32
1 Question 3 Image 1 Answer 33
To do this I have made the following assumption
You want each Question Text to appear as a new question with it's own associated answers
I would implement this using a List in SSRS
Add a new List item, and set it's DataSetName to your Dataset. (I have also set the BorderStyle to Solid in the example below)
Right click the Row Header, and select Row Group -> Group Properties, then Group on QuestionName
Within the body of the list item, draw a textbox for the Question name, and Create a Placeholder in it with the value =Fields!QuestionName.Value
Add a new image box, and set it to use the image =Fields!Image.Value
Finally add a new table, and set the data to be =Fields!AnswerText.Value. (You may also want to remove the header row)
The final layout should be something like this
And when run will render as
Hopefully this is the sort of thing you are after. If not then let us know to provide further assistance.

SQL mass replace column value [duplicate]

This question already has answers here:
MySQL string replace
(6 answers)
Closed 8 years ago.
I have a database with a table name called mybb_users.
All users have a field name called avatar. Some users have their avatar set as
http://graph.facebook.com/userid/picture?width=250&height=250.
I want to mass-replace all the width and height of the people that use a facebook picture with this amount of width and height. I unfortunately don't know how to do this since the userid is random. Is there anyway I can mass replace width=250&height=250 to width=140&height=140 ?
Thank you!
you can do it with the REPLACE function:
UPDATE mybb_users
SET avatar = REPLACE(`avatar`, 'width=250&height=250', 'width=140&height=140')
WHERE avatar like '%graph.facebook%'
for further information have a look at: http://dev.mysql.com/doc/refman/5.6/en/string-functions.html#function_replace
You can update just the portion you want like this:
UPDATE mybb_users SET avatar = REPLACE(avatar, 'width=250&height=250', 'width=140&height=140')
this should replace all occurences of the 250 with 140

Python What is 'List Slicing' [duplicate]

This question already has answers here:
Understanding slicing
(38 answers)
Closed 9 years ago.
Very simple (and potentially stupid question)
What is 'List Slicing' in python and can someone please give an example of list slicing.
Thanks !
List slicing is creating a new list containing the requested elements.
a = ['spam', 'eggs', 100, 1234]
This means that the following slice returns a shallow copy of the list a:
>>> a[:]
['spam', 'eggs', 100, 1234]
An example would be accessing the first three items of an array like so:
arr[:3]
There are many other examples on this page:
http://docs.python.org/2/tutorial/introduction.html