I have install Sakai version 12, I encountered the following problem: The input score for the question was 0.525 but after clicking the Save button the score became 0.53. I tried to reconfigure the sakai.properties file at line gradebook.class.average.decimal.places and assignment.grading.decimals but failed.
I have attached the picture, expect anyone to help me.
Thanks!
Picture 1: http://prntscr.com/j36o75
Picture 2: http://prntscr.com/j36ogy Picture 3: http://prntscr.com/j36on1 Picture 4: http://prntscr.com/j36ork
From your pictures it looks like you're referring to Tests & Quizzes rather than assignment. It looks like T&Q (Samigo) is hardcoded to only be 2 decimal places. From what I can see Gradebook is also hardcoded for individual grade items to be 2 decimal places.
You'd have to submit a feature request on Sakai's Jira or a Pull Request to allow these values to be configured. There may be some loss in precision if too many decimal places are supported.
samigo-app/src/java/org/sakaiproject/tool/assessment/ui/bean/evaluation/TotalScoresBean.java
359: String newmax= ContextUtil.getRoundedValue(maxScore, 2);
samigo-app/src/java/org/sakaiproject/tool/assessment/ui/bean/evaluation/AgentResults.java
241: String newscore = ContextUtil.getRoundedValue(totalAutoScore.replace(',', '.'), 2);
270: String newscore = ContextUtil.getRoundedValue(
296: String newscore = ContextUtil.getRoundedValue(finalScore.replace(',', '.'), 2);
samigo-app/src/java/org/sakaiproject/tool/assessment/ui/bean/delivery/DeliveryBean.java
1253: String newscore= ContextUtil.getRoundedValue(rawScore, 2);
1272: String newscore= ContextUtil.getRoundedValue(rawScore, 2);
samigo-app/src/java/org/sakaiproject/tool/assessment/ui/bean/delivery/DeliveryBeanie.java
382: String newscore= ContextUtil.getRoundedValue(rawScore, 2);
samigo-app/src/java/org/sakaiproject/tool/assessment/ui/listener/util/ContextUtil.java
334: public static String getRoundedValue(String orig, int maxdigit) {
336: return getRoundedValue(origdouble, maxdigit);
338: public static String getRoundedValue(Double orig, int maxdigit) {
Related
I am creating a BMI Ideal Weight calculator where the user is prompted to input data or there information into the textboxes, such as their name, height, weight (the weight can be in metric aka kgs or in imperial aka pounds) and the height can either be in metres or in feet. I also am using a radiobutton, two different ones to distinguish between genders (male or female) because males and females have different BMIs. The information and formulas I'm supposed to refer to is in the photo below, but my problem is so far when I am coding it and I'm just testing out for the male radio button because I completed it, nothing is outputting into my jLabel aka lblOutput...
Here is a quick rundown of what I want:
1)User is prompted to click on gender (radiobutton)
2)User is then needed to fill in the information
3)Supposed to output BMI and telling the person if it's normal, underweight, etc.
Here is the code (So far what I have):
String name = txt1.getText();
double Metric = Double.parseDouble(txt2.getText());
double Imperial = Double.parseDouble(txt2.getText());
double metres = Double.parseDouble(txt3.getText());
double inches = Double.parseDouble(txt4.getText());
double kgs = Double.parseDouble(txt5.getText());
double pounds = Double.parseDouble(txt5.getText());
double weight;
double weight2;
int m = 1;
int i =2;
int me =3;
int in=4;
if (rdbMale.isSelected()) {
if (Metric==m) {
//inches = System.null(); //need to learn how to make it null or dissapear if user inputs for metric instead of imperial
weight = metres/Math.pow(kgs, 2);
lblOutput.setText("Your name is " + name + " and your ideal weight in kgs is " + String.format("%.2f", weight));
}
} else if (Imperial==i) {
weight2 = inches/Math.pow(pounds, 2)*703;
lblOutput.setText("Your name is " + name + " and your ideal weight in pounds is " + String.format("%.2f", weight2));
}
// some codes are unneccessary like the int me, or the int in i used them so i can distinguish between which one the user wants to chose from either 3 for metres or 4 for inches, pls ignore that
//I basically just want this to work and I don't know how to get it to work
I try to read the values from a cell as a String (as one would see it in Excel). I reads from a xlsx (XSSFWorkbook) using Apache POI 3.15.
My goal is e.g. to omit decimal point and trailing zeros if the cell contains an integer. This works for CellType.NUMERIC:
val dataFormatter = new DataFormatter(true) // set emulateCsv to true
val stringValue = dataFormatter.formatCellValue(cell)
If I use the same code for CellType.FORMULA cell (e.g. a cell which references another "integer" cell), it just gives me the formula as a string instead of its computed value.
How can I get value of the formula-cell as displayed in Excel displays?
You need to "evaluate" cells in order to get the result of formulas. This is not done automatically by POI as it can be a heavy operation and often will not be necessary.
See http://poi.apache.org/spreadsheet/eval.html for details, basically you create a FormulaEvaluator and retrieve a CellValue for the Cell in question
FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
...
CellValue cellValue = evaluator.evaluate(cell);
Thanks to Centic and Raphael I ended up using the concept with NumberFormat to fix an issue, this is Java but I am sure it can easily be converted to Scala
The issue is around numbers with decimal places which produces scientific decimal points.
This was only required when converting Apache POI XLS / XLSX to CSV format
//Create an evaluator from current work book
FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
// Cell cell2 = evaluator.evaluateInCell(cell);
// As per above get CellValue
CellValue cellValue = evaluator.evaluate(cell);
//Get Double Value of formula which may contain E numbers
Double value = cellValue.getNumberValue();
// This gets numberFormat (below function) and assigns correct formatting to it
NumberFormat formatter = getNumberFormat(value);
//This should now be string value of number with correct decimal place values (non scientific)
formatter.format(value)
/**
* getNumberFormat takes number and either assigns #0
* if no decimal places or
* depending on how many numbers after decimal place assigns correct format
*/
public static NumberFormat getNumberFormat(Double value) {
String v = value.toString();
String format = "#0";
// This fixes scientific value issue
if (v.contains(".")) {
int decimals = v).substring(v.indexOf(".") + 1).length();
//Calls generateNumberSigns based on decimal places in given double
String numberSigns = generateNumberSigns(decimals);
format = "0." + numberSigns;
}
return new DecimalFormat(format);
}
/**
* This will generate correct formula for amount of decimal places
*/
public static String generateNumberSigns(int n) {
String s = "";
for (int i = 0; i < n; i++) {
s += "#";
}
return s;
}
Given a number, I'd like to transform it into a string, but insert commas in the thousands place etc, like:
int number = 123456;
String formatted = String.valueOf(number);
println(formatted); // but print "123,456"?
does GWT offer a way of doing this, or should we write our own method?
Thanks
The first one is to format a number with decimal points and include a comma. The other is with out decimal points. I'm giving this out because it wasn't so easy for me to figure it out the first time when I was starting out.
private NumberFormat decFormat = NumberFormat.getFormat("#,##0.00;(#,##0.00)");
private NumberFormat intFormat = NumberFormat.getFormat("#,##0;(#,##0)");
Use NumberFormat provided by GWT.
I'm not quite sure what to call it, but I have a text field to hold a currency value, so I'm storing that as a NSDecimalNumber. I don't want to use the numbers & symbols keyboard so I'm using a number pad, and inferring the location of a decimal place like ATMs do. It works fine for entering numbers. Type 1234 and it displays $12.34 but now I need to implement back space. So assuming $12.34 is entered hitting back space would show $1.23. I'm not quite sure how to do this with a decimal number. With an int you would just divide by 10 to remove the right most digit, but that obviously doesn't work here. I could do it by some messy converting to int / 10 then back to decimal but that just sounds horrific... Any suggestions?
Call - (NSDecimalNumber *)decimalNumberByDividingBy:(NSDecimalNumber *)decimalNumber withBehavior:(id < NSDecimalNumberBehaviors >)behavior on it
How about using stringValue?
1) NSDecimalNumber to String
2) substring last
3) String to NSDecimalNumber
Below is an example for Swift 3
func popLastNumber(of number: NSDecimalNumber) -> NSDecimalNumber {
let stringFromNumber = number.stringValue //NSNumber property
let lastIndex = stringFromNumber.endIndex
let targetIndex = stringFromNumber.index(before: lastIndex)
let removed = stringFromNumber.substring(to: targetIndex)
return NSDecimalNumber(string: removed)
}
If your input number is a single digit, it would return NaN.
You could replace it to NSDecimalNumber.zero if you need.
It may works like delete button on calcultor.
It's not tested much.
If someone found another NaN case, please report by reply.
I am a beginner.
Using Java-Eclipse SDK, How can I Take 2 numbers as input, print the sum?
I cannot open a project! Please can some one help me, telling me step by step what to do?
Thanks..
Tanvir
Are you trying to create a Java project, take two numbers as output, and print the sum? If that is true, you should really read over some basic Java/Eclipse tutorials. I would suggest the Eclipse and Java Tutorial for Total Beginners -- it should get you started on how to create/open a project and how to use eclipse.
As for getting two numbers and printing out the sum, you should really learn Java IO and do this yourself, but a quick google search gets exactly what you want:
import java.io.*; //imports java.io class
/*
* Adds 2 integers given by the user, then prints out the sum.
* Directly copied from http://www.dreamincode.net/code/snippet492.htm, as I
* am too lazy to write this myself :)
*/
public class Add2number {
//main(): application entry point
public static void main(String[] args) throws IOException {
//set input stream
BufferedReader stdin = new BufferedReader(
new InputStreamReader(System.in));
//get numbers from user input
//asks user for 1st number, then converts it to an integer
System.out.print("Enter first integer: ");
int x = Integer.parseInt(stdin.readLine());
//asks user for 2nd number, than converts it to an integer
System.out.print("Enter second integer: ");
int y = Integer.parseInt(stdin.readLine());
//add x,y
int sum = x + y;
//Display sum of x,y
System.out.println("The sum is: " + sum);
}//ends main
}//ends addReadLine