From the course: Java 11+ Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Manage currency values with BigDecimal - Java Tutorial
From the course: Java 11+ Essential Training
Manage currency values with BigDecimal
- [Instructor] Primitive numeric types are useful for storing single values in memory. But specifically, double and float types aren't always entirely precise. That's because the way they're stored in memory, doesn't always map exactly to the value. You can look at the documentation for the details of this, but it's better just to see an example. I'll go into jshell and I'm going to create a variable named value to have that explicitly type as a primitive double. And I'll assign it a value of .012. Now, I'm going to add that value together three times. And I'm going to create a new double variable that I'll call pSum, I'm using the letter p for primitive, and I'll give it a value of value + value + value. Now before I show you the result, take a guess at what that should be. You might guess it's .036, but instead, you get .036 and a whole bunch of zeroes, followed by a number at the end. So particularly, when you're…
Contents
-
-
-
-
-
(Locked)
Work with primitive variables5m 43s
-
(Locked)
Declare and modify primitive values3m 27s
-
(Locked)
Declare and initialize object variables3m 40s
-
(Locked)
Manage currency values with BigDecimal3m 8s
-
(Locked)
Convert values between numeric types2m 40s
-
(Locked)
Math operators and the Math class2m 22s
-
(Locked)
Manage true and false Boolean values2m 43s
-
Manage character values as primitives3m 13s
-
(Locked)
More about Java operators5m 45s
-
(Locked)
-
-
-
-
-
-
-