SlideShare una empresa de Scribd logo
1 de 13
Descargar para leer sin conexión
Calculations in Java with open source APICalculations in Java with open source APICalculations in Java with open source APICalculations in Java with open source API
Author: Davor Sauer
www.jdice.org
Content
Calculations in Java- basics
Calculations in Java with JCalc
Comparison of complex calculation with plain Java and
Features
Questions
of complex calculation with plain Java and JCalc
Calculations in Java-
Example: Simple calculation: If you pay $2.00 for a beer that costs $1.10,
how much changes do you get?
System.out.println(2.00 - 1.10); Answers:
a)
b)
c)
d)
gDecimal payment = new BigDecimal(2.00); Answers:gDecimal payment = new BigDecimal(2.00);
gDecimal cost = new BigDecimal(1.10);
ystem.out.println(payment.subtract(cost));
Answers:
a)
b)
c)
d)
=> 0.89999999991118215802998747...
gDecimal payment = new BigDecimal("2.00");
gDecimal cost = new BigDecimal("1.10");
ystem.out.println(payment.subtract(cost));
Answers:
a)
b)
c)
d)
- basics
Simple calculation: If you pay $2.00 for a beer that costs $1.10,
Answers:
.9
.90
0.899999999999
None of the above
Answers:Answers:
.9
.90
0.899999999999
None of the above
=> 0.89999999991118215802998747...
Answers:
.9
0.90
0.899999999999
None of the above
ava + JCalc
...more sugar?
Calculations in Java-
Example: Simple calculation: If you pay $2.00 for a beer that costs $1.10,
how much changes do you get?
System.out.println(Calculator.builder().val(2.00).sub(1.10).
m p = new Num(2.00);
m c = new Num(1.10);m c = new Num(1.10);
tem.out.println(Calculator.builder().val(p).sub(c).calculate
m p = new Num("2.00");
m c = new Num("1.10");
tem.out.println(Calculator.builder().val(p).sub(c).setStripTrailingZeros
tem.out.println(Calculator.builder("2.00 - 1.10").setStripTrailingZeros
- basics
Simple calculation: If you pay $2.00 for a beer that costs $1.10,
().val(2.00).sub(1.10).calculate());
Answers:
a) 0.9
b) .90
c) 0.899999999999
d) None of the above
0.899999999999
d) None of the above
calculate()); Answers:
a) .9
b) .90
c) 0.899999999999
d) None of the above
setStripTrailingZeros(false).calculate());
setStripTrailingZeros(false).calculate());
Answers:
a) .9
b) 0.90
c) 0.89999999
d) None of th
0.9
0.89999999991118215802998747...
Complex example
Calculate fixed monthly payment for a fixed rate mortgage by Java
ecimal interestRate = new BigDecimal("6.5"); // fixed yearly interest rate in %
ecimal P = new BigDecimal(200000);
ecimal paymentYears = new BigDecimal(30);
onthly interest rate => 6.5 / 12 / 100 = 0.0054166667
ecimal r = interestRate.divide(new BigDecimal(12), 10, BigDecimal.ROUND_HALF_UP).divide(new
umerator
> 0.005416666 * 200000 = 1083.3333400000
ecimal numerator = r.multiply(P);
enominatorenominator
.add(new BigDecimal(1)); // => 1.0054166667
ecimal pow = new BigDecimal(30 * 12); // N = 30 * 12
> 1.005416666 ^ (-30 * 12) ===> 1 / 1.005416666 ^ (30 * 12)
ecimal one = BigDecimal.ONE;
ecimal r_pow = r.pow(pow.intValue()); // => 1.0054166667 ^ 360 = 6.99179805731691416804....
w = one.divide(r_pow, 10, BigDecimal.ROUND_HALF_UP); // => 1 / 6.991798.. = 0.1430247258
> 1 - 0.1430247258 = 0.8569752742
ecimal denominator = new BigDecimal(1);
minator = denominator.subtract(r_pow);
> 1083.3333400000 / 0.8569752742 = 1264.1360522464
ecimal c = numerator.divide(denominator, 10, BigDecimal.ROUND_HALF_UP);
.setScale(2, BigDecimal.ROUND_HALF_UP);
em.out.println("c = " + c);
Calculate fixed monthly payment for a fixed rate mortgage by Java
).divide(new BigDecimal(100), 10, BigDecimal.ROUND_HALF_UP);
// => 1.0054166667 ^ 360 = 6.99179805731691416804....
// => 1 / 6.991798.. = 0.1430247258
Line of code: 15
Complex example
Calculate fixed monthly payment for a fixed rate mortgage by Java
m interestRate = new Num(6.5); // fixed yearly interest rate in %
m P = new Num(200000);
m paymentYears = new Num(30);
monthly interest rate : r = 6.5 / 100 / 12
m r = Calculator.builder().openBracket().val(interestRate).div(100).closeBracket().div(12).calculate();
= 30 * 12 * -1
m N = Calculator.builder().val(paymentYears).mul(12).mul(-1).calculate();
= (r * P) / (1 / (1 + r)^N
ulator c = new Calculator()
= (r * P) / (1 / (1 + r)^N
ulator c = new Calculator()
.openBracket()
.val(r).mul(P)
.closeBracket() // numerator
.div() // ---------------
.openBracket() // denumerator
.val(1).sub().openBracket().val(1).add(r).closeBracket
.closeBracket();
m result = c.calculate().setScale(2);
em.out.println("c = " + result); Line
Calculate fixed monthly payment for a fixed rate mortgage by Java
().div(12).calculate();
closeBracket().pow(N)
Line of code: 8
Complex example
Calculate fixed monthly payment for a fixed rate mortgage by Java
m interestRate = new Num("A", 6.5);
m P = new Num("B", 200000);
m paymentYears = new Num("C", -30);
ulator c = Calculator.builder("((A / 100 / 12) * B) / (1 - ((1 + (A / 100 / 12)) ^ (C * 12)))",
m result = c.calculate();
em.out.println("c = " + result.setScale(2));
Line
Calculate fixed monthly payment for a fixed rate mortgage by Java
((1 + (A / 100 / 12)) ^ (C * 12)))", interestRate, P, paymentYears);
Line of code: 6
Feature: Show calculation
Num interestRate = new Num("A", 6.5);
Num P = new Num("B", 200000);
Num paymentYears = new Num("C", -30);
Calculator c = Calculator.builder("((A / 100 / 12) * B) / (1 - ((1 + (A / 100 / 12)) ^ (C * 12)))",
c.setScale(10);
Num result = c.calculate(true, false); // track calculation steps, track details
for(String step : c.getCalculationSteps())
System.out.println(step);
System.out.println("c = " + result.setScale(2));
Output:
6.5 / 100 = 0.065
0.065/ 12 = 0.0054166667
0.0054166667 * 200000
6.5 / 100 = 0.065
0.065/ 12 = 0.0054166667
1 + 0.0054166667
-30 * 12 = -360
1.0054166667 ^ -360
1 - 0.1430247258
1083.33334/ 0.8569752742
c = 1264.14
calculation steps
((1 + (A / 100 / 12)) ^ (C * 12)))", interestRate, P, paymentYears);
= 0.065
= 0.0054166667
* 200000 = 1083.33334
= 0.065
= 0.0054166667
+ 0.0054166667 = 1.0054166667
360 = 0.1430247258
= 0.8569752742
/ 0.8569752742 = 1264.1360522464
Feature: Modularity
Calculator calc = new Calculator();
calc.register(QuestionOperator.class); // register custom operator '?'
calc.register(SumFunction.class); // register custom function 'sum'
calc.expression("2 ? 2 + 5 - 1 + sum(1,2,3,4)");
@SingletonComponent@SingletonComponent
public class QuestionOperator implements Operator {
....
// module for ‘?’ operator
....
}
@SingletonComponent
public class SumFunction implements Function {
....
// module for function ‘sum’
....
}
// register custom operator '?'
register custom function 'sum'
implements Operator {
Feature: Default configuration
roundingMode=HALF_UP
scale=2
stripTrailingZeros=true
decimalSeparator.out='.'
decimalSeparator.in='.'
numconverter[0]=org.jdice.calc.test.NumTest$CustomObject > org.jdice.calc.test.NumTest$CustomObjectNumConverter
Configure default properties with 'jcalc.properties' file in class path
numconverter[0]=org.jdice.calc.test.NumTest$CustomObject > org.jdice.calc.test.NumTest$CustomObjectNumConverter
operator[0]=org.jdice.calc.test.CustomOperatorFunctionTest$QuestionOperator
function[0]=org.jdice.calc.test.CustomOperatorFunctionTest$SumFunction
configuration
org.jdice.calc.test.NumTest$CustomObjectNumConverter
' file in class path
org.jdice.calc.test.NumTest$CustomObjectNumConverter
org.jdice.calc.test.CustomOperatorFunctionTest$QuestionOperator
org.jdice.calc.test.CustomOperatorFunctionTest$SumFunction
ions, ideas, suggestions…
Project page: www.jdice.org

Más contenido relacionado

La actualidad más candente

Critical buckling load geometric nonlinearity analysis of springs with rigid ...
Critical buckling load geometric nonlinearity analysis of springs with rigid ...Critical buckling load geometric nonlinearity analysis of springs with rigid ...
Critical buckling load geometric nonlinearity analysis of springs with rigid ...Salar Delavar Qashqai
 
Amth250 octave matlab some solutions (4)
Amth250 octave matlab some solutions (4)Amth250 octave matlab some solutions (4)
Amth250 octave matlab some solutions (4)asghar123456
 
Numerical Method Assignment
Numerical Method AssignmentNumerical Method Assignment
Numerical Method Assignmentashikul akash
 
Pytorch and Machine Learning for the Math Impaired
Pytorch and Machine Learning for the Math ImpairedPytorch and Machine Learning for the Math Impaired
Pytorch and Machine Learning for the Math ImpairedTyrel Denison
 
Oops lab manual2
Oops lab manual2Oops lab manual2
Oops lab manual2Mouna Guru
 
Graphics programs
Graphics programsGraphics programs
Graphics programsNAVYA RAO
 
Graphics practical lab manual
Graphics practical lab manualGraphics practical lab manual
Graphics practical lab manualVivek Kumar Sinha
 
SPL 6.1 | Advanced problems on Operators and Math.h function in C
SPL 6.1 | Advanced problems on Operators and Math.h function in CSPL 6.1 | Advanced problems on Operators and Math.h function in C
SPL 6.1 | Advanced problems on Operators and Math.h function in CMohammad Imam Hossain
 
Resolución del-examen-de-la-práctica-de-métodos-numéricos
Resolución del-examen-de-la-práctica-de-métodos-numéricosResolución del-examen-de-la-práctica-de-métodos-numéricos
Resolución del-examen-de-la-práctica-de-métodos-numéricosCarlos Cosi Mamani
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manualUma mohan
 
The Ring programming language version 1.3 book - Part 47 of 88
The Ring programming language version 1.3 book - Part 47 of 88The Ring programming language version 1.3 book - Part 47 of 88
The Ring programming language version 1.3 book - Part 47 of 88Mahmoud Samir Fayed
 
Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics labPriya Goyal
 
Firefox content
Firefox contentFirefox content
Firefox contentUbald Agi
 
Mathematics Function in C ,ppt
Mathematics Function in C ,pptMathematics Function in C ,ppt
Mathematics Function in C ,pptAllNewTeach
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSKavyaSharma65
 
The Ring programming language version 1.9 book - Part 75 of 210
The Ring programming language version 1.9 book - Part 75 of 210The Ring programming language version 1.9 book - Part 75 of 210
The Ring programming language version 1.9 book - Part 75 of 210Mahmoud Samir Fayed
 

La actualidad más candente (20)

Critical buckling load geometric nonlinearity analysis of springs with rigid ...
Critical buckling load geometric nonlinearity analysis of springs with rigid ...Critical buckling load geometric nonlinearity analysis of springs with rigid ...
Critical buckling load geometric nonlinearity analysis of springs with rigid ...
 
Amth250 octave matlab some solutions (4)
Amth250 octave matlab some solutions (4)Amth250 octave matlab some solutions (4)
Amth250 octave matlab some solutions (4)
 
Numerical Method Assignment
Numerical Method AssignmentNumerical Method Assignment
Numerical Method Assignment
 
Struct examples
Struct examplesStruct examples
Struct examples
 
Recursion in C
Recursion in CRecursion in C
Recursion in C
 
Pytorch and Machine Learning for the Math Impaired
Pytorch and Machine Learning for the Math ImpairedPytorch and Machine Learning for the Math Impaired
Pytorch and Machine Learning for the Math Impaired
 
Oops lab manual2
Oops lab manual2Oops lab manual2
Oops lab manual2
 
Experement no 6
Experement no 6Experement no 6
Experement no 6
 
Graphics programs
Graphics programsGraphics programs
Graphics programs
 
Graphics practical lab manual
Graphics practical lab manualGraphics practical lab manual
Graphics practical lab manual
 
SPL 6.1 | Advanced problems on Operators and Math.h function in C
SPL 6.1 | Advanced problems on Operators and Math.h function in CSPL 6.1 | Advanced problems on Operators and Math.h function in C
SPL 6.1 | Advanced problems on Operators and Math.h function in C
 
Resolución del-examen-de-la-práctica-de-métodos-numéricos
Resolución del-examen-de-la-práctica-de-métodos-numéricosResolución del-examen-de-la-práctica-de-métodos-numéricos
Resolución del-examen-de-la-práctica-de-métodos-numéricos
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
Arrays
ArraysArrays
Arrays
 
The Ring programming language version 1.3 book - Part 47 of 88
The Ring programming language version 1.3 book - Part 47 of 88The Ring programming language version 1.3 book - Part 47 of 88
The Ring programming language version 1.3 book - Part 47 of 88
 
Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics lab
 
Firefox content
Firefox contentFirefox content
Firefox content
 
Mathematics Function in C ,ppt
Mathematics Function in C ,pptMathematics Function in C ,ppt
Mathematics Function in C ,ppt
 
LET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERSLET US C (5th EDITION) CHAPTER 2 ANSWERS
LET US C (5th EDITION) CHAPTER 2 ANSWERS
 
The Ring programming language version 1.9 book - Part 75 of 210
The Ring programming language version 1.9 book - Part 75 of 210The Ring programming language version 1.9 book - Part 75 of 210
The Ring programming language version 1.9 book - Part 75 of 210
 

Destacado

Destacado (20)

JavaCro'14 - WebLogic-GlassFish-JaaS Strategy and Roadmap – Duško Vukmanović
JavaCro'14 - WebLogic-GlassFish-JaaS Strategy and Roadmap – Duško VukmanovićJavaCro'14 - WebLogic-GlassFish-JaaS Strategy and Roadmap – Duško Vukmanović
JavaCro'14 - WebLogic-GlassFish-JaaS Strategy and Roadmap – Duško Vukmanović
 
JavaCro'14 - WebSockets and OpenLayers joined with Spring – Bojan Kljajin
JavaCro'14 - WebSockets and OpenLayers joined with Spring – Bojan KljajinJavaCro'14 - WebSockets and OpenLayers joined with Spring – Bojan Kljajin
JavaCro'14 - WebSockets and OpenLayers joined with Spring – Bojan Kljajin
 
JavaCro'14 - The World of Java – in Croatia – Branko Mihaljević and Aleksande...
JavaCro'14 - The World of Java – in Croatia – Branko Mihaljević and Aleksande...JavaCro'14 - The World of Java – in Croatia – Branko Mihaljević and Aleksande...
JavaCro'14 - The World of Java – in Croatia – Branko Mihaljević and Aleksande...
 
JavaCro'14 - Going Digital with Java EE - Peter Pilgrim
JavaCro'14 - Going Digital with Java EE - Peter PilgrimJavaCro'14 - Going Digital with Java EE - Peter Pilgrim
JavaCro'14 - Going Digital with Java EE - Peter Pilgrim
 
JavaCro'14 - Sustainability of business performance and best practices – Zlat...
JavaCro'14 - Sustainability of business performance and best practices – Zlat...JavaCro'14 - Sustainability of business performance and best practices – Zlat...
JavaCro'14 - Sustainability of business performance and best practices – Zlat...
 
JavaCro'14 - Can You Tell Me How to Get to Sesame Street I wanna be a Grails ...
JavaCro'14 - Can You Tell Me How to Get to Sesame Street I wanna be a Grails ...JavaCro'14 - Can You Tell Me How to Get to Sesame Street I wanna be a Grails ...
JavaCro'14 - Can You Tell Me How to Get to Sesame Street I wanna be a Grails ...
 
JavaCro'14 - Automatized testing with Selenium 2 – Juraj Ćutić and Aleksander...
JavaCro'14 - Automatized testing with Selenium 2 – Juraj Ćutić and Aleksander...JavaCro'14 - Automatized testing with Selenium 2 – Juraj Ćutić and Aleksander...
JavaCro'14 - Automatized testing with Selenium 2 – Juraj Ćutić and Aleksander...
 
JavaCro'14 - Amphinicy crown jewels our software development infrastructure –...
JavaCro'14 - Amphinicy crown jewels our software development infrastructure –...JavaCro'14 - Amphinicy crown jewels our software development infrastructure –...
JavaCro'14 - Amphinicy crown jewels our software development infrastructure –...
 
JavaCro'14 - Auditing of user activity through NoSQL database – Kristijan Duv...
JavaCro'14 - Auditing of user activity through NoSQL database – Kristijan Duv...JavaCro'14 - Auditing of user activity through NoSQL database – Kristijan Duv...
JavaCro'14 - Auditing of user activity through NoSQL database – Kristijan Duv...
 
JavaCro'14 - Java in M2M technologies – Mango M2M software – Ivan Raguž
JavaCro'14 - Java in M2M technologies – Mango M2M software – Ivan RagužJavaCro'14 - Java in M2M technologies – Mango M2M software – Ivan Raguž
JavaCro'14 - Java in M2M technologies – Mango M2M software – Ivan Raguž
 
JavaCro'14 - Cloud Platforms in Internet of Things – Krešimir Mišura and Bran...
JavaCro'14 - Cloud Platforms in Internet of Things – Krešimir Mišura and Bran...JavaCro'14 - Cloud Platforms in Internet of Things – Krešimir Mišura and Bran...
JavaCro'14 - Cloud Platforms in Internet of Things – Krešimir Mišura and Bran...
 
JavaCro'14 - Take Agile adoption to the next level with Integration Competenc...
JavaCro'14 - Take Agile adoption to the next level with Integration Competenc...JavaCro'14 - Take Agile adoption to the next level with Integration Competenc...
JavaCro'14 - Take Agile adoption to the next level with Integration Competenc...
 
JavaCro'14 - MEAN Stack – How & When – Nenad Pećanac
JavaCro'14 - MEAN Stack – How & When – Nenad PećanacJavaCro'14 - MEAN Stack – How & When – Nenad Pećanac
JavaCro'14 - MEAN Stack – How & When – Nenad Pećanac
 
JavaCro'14 - ZeroMQ and Java(Script) – Mladen Čikara
JavaCro'14 - ZeroMQ and Java(Script) – Mladen ČikaraJavaCro'14 - ZeroMQ and Java(Script) – Mladen Čikara
JavaCro'14 - ZeroMQ and Java(Script) – Mladen Čikara
 
JavaCro'14 - Packaging and installing of the JEE solution – Miroslav Rešetar
JavaCro'14 - Packaging and installing of the JEE solution – Miroslav RešetarJavaCro'14 - Packaging and installing of the JEE solution – Miroslav Rešetar
JavaCro'14 - Packaging and installing of the JEE solution – Miroslav Rešetar
 
JavaCro'14 - Profile any environment with Java Flight Recorder – Johan Janssen
JavaCro'14 - Profile any environment with Java Flight Recorder – Johan JanssenJavaCro'14 - Profile any environment with Java Flight Recorder – Johan Janssen
JavaCro'14 - Profile any environment with Java Flight Recorder – Johan Janssen
 
JavaCro'14 - Continuous deployment tool – Aleksandar Dostić and Emir Džaferović
JavaCro'14 - Continuous deployment tool – Aleksandar Dostić and Emir DžaferovićJavaCro'14 - Continuous deployment tool – Aleksandar Dostić and Emir Džaferović
JavaCro'14 - Continuous deployment tool – Aleksandar Dostić and Emir Džaferović
 
JavaCro'14 - Drools Decision tables – form of human-readable rules – Dragan J...
JavaCro'14 - Drools Decision tables – form of human-readable rules – Dragan J...JavaCro'14 - Drools Decision tables – form of human-readable rules – Dragan J...
JavaCro'14 - Drools Decision tables – form of human-readable rules – Dragan J...
 
JavaCro'14 - Is there a single “correct” web architecture for business apps –...
JavaCro'14 - Is there a single “correct” web architecture for business apps –...JavaCro'14 - Is there a single “correct” web architecture for business apps –...
JavaCro'14 - Is there a single “correct” web architecture for business apps –...
 
JavaCro'14 - GWT rebooted – Gordan Krešić
JavaCro'14 - GWT rebooted – Gordan KrešićJavaCro'14 - GWT rebooted – Gordan Krešić
JavaCro'14 - GWT rebooted – Gordan Krešić
 

Similar a JavaCro'14 - JCalc Calculations in Java with open source API – Davor Sauer

Compose Async with RxJS
Compose Async with RxJSCompose Async with RxJS
Compose Async with RxJSKyung Yeol Kim
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Mario Fusco
 
PID Tuning using Ziegler Nicholas - MATLAB Approach
PID Tuning using Ziegler Nicholas - MATLAB ApproachPID Tuning using Ziegler Nicholas - MATLAB Approach
PID Tuning using Ziegler Nicholas - MATLAB ApproachWaleed El-Badry
 
Informatics Practice Practical for 12th class
Informatics Practice Practical for 12th classInformatics Practice Practical for 12th class
Informatics Practice Practical for 12th classphultoosks876
 
Super TypeScript II Turbo - FP Remix (NG Conf 2017)
Super TypeScript II Turbo - FP Remix (NG Conf 2017)Super TypeScript II Turbo - FP Remix (NG Conf 2017)
Super TypeScript II Turbo - FP Remix (NG Conf 2017)Sean May
 
Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Palak Sanghani
 
Aplicaciones de la derivada en la Carrera de Contabilidad y Auditoría
Aplicaciones de la derivada en la Carrera de Contabilidad y AuditoríaAplicaciones de la derivada en la Carrera de Contabilidad y Auditoría
Aplicaciones de la derivada en la Carrera de Contabilidad y AuditoríaLeslieMoncayo1
 
A few solvers for portfolio selection
A few solvers for portfolio selectionA few solvers for portfolio selection
A few solvers for portfolio selectionBogusz Jelinski
 
Hello, I need some assistance in writing a java program THAT MUST US.pdf
Hello, I need some assistance in writing a java program THAT MUST US.pdfHello, I need some assistance in writing a java program THAT MUST US.pdf
Hello, I need some assistance in writing a java program THAT MUST US.pdfFashionColZone
 

Similar a JavaCro'14 - JCalc Calculations in Java with open source API – Davor Sauer (20)

662305 11
662305 11662305 11
662305 11
 
Compose Async with RxJS
Compose Async with RxJSCompose Async with RxJS
Compose Async with RxJS
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
 
662305 LAB13
662305 LAB13662305 LAB13
662305 LAB13
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 
Test2
Test2Test2
Test2
 
F
FF
F
 
F
FF
F
 
F
FF
F
 
F
FF
F
 
PID Tuning using Ziegler Nicholas - MATLAB Approach
PID Tuning using Ziegler Nicholas - MATLAB ApproachPID Tuning using Ziegler Nicholas - MATLAB Approach
PID Tuning using Ziegler Nicholas - MATLAB Approach
 
Informatics Practice Practical for 12th class
Informatics Practice Practical for 12th classInformatics Practice Practical for 12th class
Informatics Practice Practical for 12th class
 
6
66
6
 
Super TypeScript II Turbo - FP Remix (NG Conf 2017)
Super TypeScript II Turbo - FP Remix (NG Conf 2017)Super TypeScript II Turbo - FP Remix (NG Conf 2017)
Super TypeScript II Turbo - FP Remix (NG Conf 2017)
 
Method overriding in java
Method overriding in javaMethod overriding in java
Method overriding in java
 
Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]
 
Aplicaciones de la derivada en la Carrera de Contabilidad y Auditoría
Aplicaciones de la derivada en la Carrera de Contabilidad y AuditoríaAplicaciones de la derivada en la Carrera de Contabilidad y Auditoría
Aplicaciones de la derivada en la Carrera de Contabilidad y Auditoría
 
A few solvers for portfolio selection
A few solvers for portfolio selectionA few solvers for portfolio selection
A few solvers for portfolio selection
 
Hello, I need some assistance in writing a java program THAT MUST US.pdf
Hello, I need some assistance in writing a java program THAT MUST US.pdfHello, I need some assistance in writing a java program THAT MUST US.pdf
Hello, I need some assistance in writing a java program THAT MUST US.pdf
 

Más de HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association

Más de HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association (20)

Java cro'21 the best tools for java developers in 2021 - hujak
Java cro'21   the best tools for java developers in 2021 - hujakJava cro'21   the best tools for java developers in 2021 - hujak
Java cro'21 the best tools for java developers in 2021 - hujak
 
JavaCro'21 - Java is Here To Stay - HUJAK Keynote
JavaCro'21 - Java is Here To Stay - HUJAK KeynoteJavaCro'21 - Java is Here To Stay - HUJAK Keynote
JavaCro'21 - Java is Here To Stay - HUJAK Keynote
 
Javantura v7 - Behaviour Driven Development with Cucumber - Ivan Lozić
Javantura v7 - Behaviour Driven Development with Cucumber - Ivan LozićJavantura v7 - Behaviour Driven Development with Cucumber - Ivan Lozić
Javantura v7 - Behaviour Driven Development with Cucumber - Ivan Lozić
 
Javantura v7 - The State of Java - Today and Tomowwow - HUJAK's Community Key...
Javantura v7 - The State of Java - Today and Tomowwow - HUJAK's Community Key...Javantura v7 - The State of Java - Today and Tomowwow - HUJAK's Community Key...
Javantura v7 - The State of Java - Today and Tomowwow - HUJAK's Community Key...
 
Javantura v7 - Learning to Scale Yourself: The Journey from Coder to Leader -...
Javantura v7 - Learning to Scale Yourself: The Journey from Coder to Leader -...Javantura v7 - Learning to Scale Yourself: The Journey from Coder to Leader -...
Javantura v7 - Learning to Scale Yourself: The Journey from Coder to Leader -...
 
JavaCro'19 - The State of Java and Software Development in Croatia - Communit...
JavaCro'19 - The State of Java and Software Development in Croatia - Communit...JavaCro'19 - The State of Java and Software Development in Croatia - Communit...
JavaCro'19 - The State of Java and Software Development in Croatia - Communit...
 
Javantura v6 - Java in Croatia and HUJAK - Branko Mihaljević, Aleksander Radovan
Javantura v6 - Java in Croatia and HUJAK - Branko Mihaljević, Aleksander RadovanJavantura v6 - Java in Croatia and HUJAK - Branko Mihaljević, Aleksander Radovan
Javantura v6 - Java in Croatia and HUJAK - Branko Mihaljević, Aleksander Radovan
 
Javantura v6 - On the Aspects of Polyglot Programming and Memory Management i...
Javantura v6 - On the Aspects of Polyglot Programming and Memory Management i...Javantura v6 - On the Aspects of Polyglot Programming and Memory Management i...
Javantura v6 - On the Aspects of Polyglot Programming and Memory Management i...
 
Javantura v6 - Case Study: Marketplace App with Java and Hyperledger Fabric -...
Javantura v6 - Case Study: Marketplace App with Java and Hyperledger Fabric -...Javantura v6 - Case Study: Marketplace App with Java and Hyperledger Fabric -...
Javantura v6 - Case Study: Marketplace App with Java and Hyperledger Fabric -...
 
Javantura v6 - How to help customers report bugs accurately - Miroslav Čerkez...
Javantura v6 - How to help customers report bugs accurately - Miroslav Čerkez...Javantura v6 - How to help customers report bugs accurately - Miroslav Čerkez...
Javantura v6 - How to help customers report bugs accurately - Miroslav Čerkez...
 
Javantura v6 - When remote work really works - the secrets behind successful ...
Javantura v6 - When remote work really works - the secrets behind successful ...Javantura v6 - When remote work really works - the secrets behind successful ...
Javantura v6 - When remote work really works - the secrets behind successful ...
 
Javantura v6 - Kotlin-Java Interop - Matej Vidaković
Javantura v6 - Kotlin-Java Interop - Matej VidakovićJavantura v6 - Kotlin-Java Interop - Matej Vidaković
Javantura v6 - Kotlin-Java Interop - Matej Vidaković
 
Javantura v6 - Spring HATEOAS hypermedia-driven web services, and clients tha...
Javantura v6 - Spring HATEOAS hypermedia-driven web services, and clients tha...Javantura v6 - Spring HATEOAS hypermedia-driven web services, and clients tha...
Javantura v6 - Spring HATEOAS hypermedia-driven web services, and clients tha...
 
Javantura v6 - End to End Continuous Delivery of Microservices for Kubernetes...
Javantura v6 - End to End Continuous Delivery of Microservices for Kubernetes...Javantura v6 - End to End Continuous Delivery of Microservices for Kubernetes...
Javantura v6 - End to End Continuous Delivery of Microservices for Kubernetes...
 
Javantura v6 - Istio Service Mesh - The magic between your microservices - Ma...
Javantura v6 - Istio Service Mesh - The magic between your microservices - Ma...Javantura v6 - Istio Service Mesh - The magic between your microservices - Ma...
Javantura v6 - Istio Service Mesh - The magic between your microservices - Ma...
 
Javantura v6 - How can you improve the quality of your application - Ioannis ...
Javantura v6 - How can you improve the quality of your application - Ioannis ...Javantura v6 - How can you improve the quality of your application - Ioannis ...
Javantura v6 - How can you improve the quality of your application - Ioannis ...
 
Javantura v6 - Just say it v2 - Pavao Varela Petrac
Javantura v6 - Just say it v2 - Pavao Varela PetracJavantura v6 - Just say it v2 - Pavao Varela Petrac
Javantura v6 - Just say it v2 - Pavao Varela Petrac
 
Javantura v6 - Automation of web apps testing - Hrvoje Ruhek
Javantura v6 - Automation of web apps testing - Hrvoje RuhekJavantura v6 - Automation of web apps testing - Hrvoje Ruhek
Javantura v6 - Automation of web apps testing - Hrvoje Ruhek
 
Javantura v6 - Master the Concepts Behind the Java 10 Challenges and Eliminat...
Javantura v6 - Master the Concepts Behind the Java 10 Challenges and Eliminat...Javantura v6 - Master the Concepts Behind the Java 10 Challenges and Eliminat...
Javantura v6 - Master the Concepts Behind the Java 10 Challenges and Eliminat...
 
Javantura v6 - Building IoT Middleware with Microservices - Mario Kusek
Javantura v6 - Building IoT Middleware with Microservices - Mario KusekJavantura v6 - Building IoT Middleware with Microservices - Mario Kusek
Javantura v6 - Building IoT Middleware with Microservices - Mario Kusek
 

Último

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 

Último (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

JavaCro'14 - JCalc Calculations in Java with open source API – Davor Sauer

  • 1. Calculations in Java with open source APICalculations in Java with open source APICalculations in Java with open source APICalculations in Java with open source API Author: Davor Sauer www.jdice.org
  • 2. Content Calculations in Java- basics Calculations in Java with JCalc Comparison of complex calculation with plain Java and Features Questions of complex calculation with plain Java and JCalc
  • 3.
  • 4. Calculations in Java- Example: Simple calculation: If you pay $2.00 for a beer that costs $1.10, how much changes do you get? System.out.println(2.00 - 1.10); Answers: a) b) c) d) gDecimal payment = new BigDecimal(2.00); Answers:gDecimal payment = new BigDecimal(2.00); gDecimal cost = new BigDecimal(1.10); ystem.out.println(payment.subtract(cost)); Answers: a) b) c) d) => 0.89999999991118215802998747... gDecimal payment = new BigDecimal("2.00"); gDecimal cost = new BigDecimal("1.10"); ystem.out.println(payment.subtract(cost)); Answers: a) b) c) d) - basics Simple calculation: If you pay $2.00 for a beer that costs $1.10, Answers: .9 .90 0.899999999999 None of the above Answers:Answers: .9 .90 0.899999999999 None of the above => 0.89999999991118215802998747... Answers: .9 0.90 0.899999999999 None of the above
  • 6. Calculations in Java- Example: Simple calculation: If you pay $2.00 for a beer that costs $1.10, how much changes do you get? System.out.println(Calculator.builder().val(2.00).sub(1.10). m p = new Num(2.00); m c = new Num(1.10);m c = new Num(1.10); tem.out.println(Calculator.builder().val(p).sub(c).calculate m p = new Num("2.00"); m c = new Num("1.10"); tem.out.println(Calculator.builder().val(p).sub(c).setStripTrailingZeros tem.out.println(Calculator.builder("2.00 - 1.10").setStripTrailingZeros - basics Simple calculation: If you pay $2.00 for a beer that costs $1.10, ().val(2.00).sub(1.10).calculate()); Answers: a) 0.9 b) .90 c) 0.899999999999 d) None of the above 0.899999999999 d) None of the above calculate()); Answers: a) .9 b) .90 c) 0.899999999999 d) None of the above setStripTrailingZeros(false).calculate()); setStripTrailingZeros(false).calculate()); Answers: a) .9 b) 0.90 c) 0.89999999 d) None of th 0.9 0.89999999991118215802998747...
  • 7. Complex example Calculate fixed monthly payment for a fixed rate mortgage by Java ecimal interestRate = new BigDecimal("6.5"); // fixed yearly interest rate in % ecimal P = new BigDecimal(200000); ecimal paymentYears = new BigDecimal(30); onthly interest rate => 6.5 / 12 / 100 = 0.0054166667 ecimal r = interestRate.divide(new BigDecimal(12), 10, BigDecimal.ROUND_HALF_UP).divide(new umerator > 0.005416666 * 200000 = 1083.3333400000 ecimal numerator = r.multiply(P); enominatorenominator .add(new BigDecimal(1)); // => 1.0054166667 ecimal pow = new BigDecimal(30 * 12); // N = 30 * 12 > 1.005416666 ^ (-30 * 12) ===> 1 / 1.005416666 ^ (30 * 12) ecimal one = BigDecimal.ONE; ecimal r_pow = r.pow(pow.intValue()); // => 1.0054166667 ^ 360 = 6.99179805731691416804.... w = one.divide(r_pow, 10, BigDecimal.ROUND_HALF_UP); // => 1 / 6.991798.. = 0.1430247258 > 1 - 0.1430247258 = 0.8569752742 ecimal denominator = new BigDecimal(1); minator = denominator.subtract(r_pow); > 1083.3333400000 / 0.8569752742 = 1264.1360522464 ecimal c = numerator.divide(denominator, 10, BigDecimal.ROUND_HALF_UP); .setScale(2, BigDecimal.ROUND_HALF_UP); em.out.println("c = " + c); Calculate fixed monthly payment for a fixed rate mortgage by Java ).divide(new BigDecimal(100), 10, BigDecimal.ROUND_HALF_UP); // => 1.0054166667 ^ 360 = 6.99179805731691416804.... // => 1 / 6.991798.. = 0.1430247258 Line of code: 15
  • 8. Complex example Calculate fixed monthly payment for a fixed rate mortgage by Java m interestRate = new Num(6.5); // fixed yearly interest rate in % m P = new Num(200000); m paymentYears = new Num(30); monthly interest rate : r = 6.5 / 100 / 12 m r = Calculator.builder().openBracket().val(interestRate).div(100).closeBracket().div(12).calculate(); = 30 * 12 * -1 m N = Calculator.builder().val(paymentYears).mul(12).mul(-1).calculate(); = (r * P) / (1 / (1 + r)^N ulator c = new Calculator() = (r * P) / (1 / (1 + r)^N ulator c = new Calculator() .openBracket() .val(r).mul(P) .closeBracket() // numerator .div() // --------------- .openBracket() // denumerator .val(1).sub().openBracket().val(1).add(r).closeBracket .closeBracket(); m result = c.calculate().setScale(2); em.out.println("c = " + result); Line Calculate fixed monthly payment for a fixed rate mortgage by Java ().div(12).calculate(); closeBracket().pow(N) Line of code: 8
  • 9. Complex example Calculate fixed monthly payment for a fixed rate mortgage by Java m interestRate = new Num("A", 6.5); m P = new Num("B", 200000); m paymentYears = new Num("C", -30); ulator c = Calculator.builder("((A / 100 / 12) * B) / (1 - ((1 + (A / 100 / 12)) ^ (C * 12)))", m result = c.calculate(); em.out.println("c = " + result.setScale(2)); Line Calculate fixed monthly payment for a fixed rate mortgage by Java ((1 + (A / 100 / 12)) ^ (C * 12)))", interestRate, P, paymentYears); Line of code: 6
  • 10. Feature: Show calculation Num interestRate = new Num("A", 6.5); Num P = new Num("B", 200000); Num paymentYears = new Num("C", -30); Calculator c = Calculator.builder("((A / 100 / 12) * B) / (1 - ((1 + (A / 100 / 12)) ^ (C * 12)))", c.setScale(10); Num result = c.calculate(true, false); // track calculation steps, track details for(String step : c.getCalculationSteps()) System.out.println(step); System.out.println("c = " + result.setScale(2)); Output: 6.5 / 100 = 0.065 0.065/ 12 = 0.0054166667 0.0054166667 * 200000 6.5 / 100 = 0.065 0.065/ 12 = 0.0054166667 1 + 0.0054166667 -30 * 12 = -360 1.0054166667 ^ -360 1 - 0.1430247258 1083.33334/ 0.8569752742 c = 1264.14 calculation steps ((1 + (A / 100 / 12)) ^ (C * 12)))", interestRate, P, paymentYears); = 0.065 = 0.0054166667 * 200000 = 1083.33334 = 0.065 = 0.0054166667 + 0.0054166667 = 1.0054166667 360 = 0.1430247258 = 0.8569752742 / 0.8569752742 = 1264.1360522464
  • 11. Feature: Modularity Calculator calc = new Calculator(); calc.register(QuestionOperator.class); // register custom operator '?' calc.register(SumFunction.class); // register custom function 'sum' calc.expression("2 ? 2 + 5 - 1 + sum(1,2,3,4)"); @SingletonComponent@SingletonComponent public class QuestionOperator implements Operator { .... // module for ‘?’ operator .... } @SingletonComponent public class SumFunction implements Function { .... // module for function ‘sum’ .... } // register custom operator '?' register custom function 'sum' implements Operator {
  • 12. Feature: Default configuration roundingMode=HALF_UP scale=2 stripTrailingZeros=true decimalSeparator.out='.' decimalSeparator.in='.' numconverter[0]=org.jdice.calc.test.NumTest$CustomObject > org.jdice.calc.test.NumTest$CustomObjectNumConverter Configure default properties with 'jcalc.properties' file in class path numconverter[0]=org.jdice.calc.test.NumTest$CustomObject > org.jdice.calc.test.NumTest$CustomObjectNumConverter operator[0]=org.jdice.calc.test.CustomOperatorFunctionTest$QuestionOperator function[0]=org.jdice.calc.test.CustomOperatorFunctionTest$SumFunction configuration org.jdice.calc.test.NumTest$CustomObjectNumConverter ' file in class path org.jdice.calc.test.NumTest$CustomObjectNumConverter org.jdice.calc.test.CustomOperatorFunctionTest$QuestionOperator org.jdice.calc.test.CustomOperatorFunctionTest$SumFunction
  • 13. ions, ideas, suggestions… Project page: www.jdice.org