Floats / Doubles And Currency

Mar 8, 2014

Just done a quick test to try and figure out the difference between floats and doubles.I made a quick program which outputs the result of 3.3 * 2 as both a float and a double.

I assumed since a float is the larger and more precise of the two data types that there would be more numbers after the decimal point, however this was not the case, it was in fact the double which had more numbers after the decimal point. Result was as follows:

Float: 29.699999
Double: 29.7

BTW for the above code I simply had a few text fields and a button with the following code:

Java Code:

textBox3.setText("" + Float.parseFloat(textBox1.getText()) * Float.parseFloat(textBox2.getText()));
textBox6.setText("" + Double.parseDouble(textBox1.getText()) * Double.parseDouble(textBox2.getText())); mh_sh_highlight_all('java');

Also, as these are limited to a certain amount of numbers im thinking there must be a more precise way for currency, if so what would I use for that? I suppose what im trying to figure out is what data type to use in different scenarios? When to use integer, float, double and long.

View Replies


ADVERTISEMENT

Currency Exchange With Java

Jun 30, 2014

I am working through a project in which I am supposed to change dollars into yen with the use of different deposits. I will post the code below that I have been working on.

import java.util.*;
public class DollartoYen {
public static final int MAX_DEPOSITS = 100;
public static final float DOLLAR_TO_YEN = 0.098f;
// read number of Dollars in each account from the keyboard
void readDollars(float[] dollars, int count ) {

[Code] .....

View Replies View Related

Currency Symbol Format - Only $ Will Be Reprinted

May 19, 2014

Java Code:

package billing.util;
import java.math.RoundingMode;
import java.text.NumberFormat;
import java.util.Scanner;
public class CurrencyFormat {
private static final int USD = 0;

[Code] .....

I should be able to use USD, CNY, and JPY. However it seems only the USD ($) will print... doesnt matter which currency symbol the user requests, only the $ will be reprinted....

View Replies View Related

Java Dicing System With Currency

Jul 31, 2014

I have been working on making a Java application for the Game RuneScape. My goal is to make an Application to where you register on the application and it saves the information in a file. I am also looking to make it so you can transfer money from Runescape to your Account on my Application by submitting a ticket. When you submit a ticket you get assisted by one of the moderators, they trade you in the game and take the money, and then they take that money out of their current account. Admins are allowed to give moderators money via their account or another method. My issue is creating the ticket system. I want to be able to do this all via the application. So basically what i have currently for the application is a chat room, with different rooms available to go into by the users. So I need to make the tickets show up only to Moderators and Admins in the general chat room.

View Replies View Related

Convert Currency Instance To Integer

Jul 26, 2014

I am working with a JFormattedTextField. After adding the text of the FormattedTextField to an LinkedList i want to read it out and sum it up. So I have a problem to convert the String to and integer...

Example:

23.00 - to 23.00
+ 11.00 - to 11.00
--> 34.00

I have tried it with splitting the string but it didn't work. How to do it?

View Replies View Related

Create A Class That Convert Currency

Feb 25, 2014

I want to create a class that converts currency. I stored 2 conversion rate as constant (final) variables. In the main method, I ask the user to enter the amount in US dollars that they want to convert. Then I ask the user to enter the currencyType ("Bitcoin" or "Chuck E Cheese").

However I am stuck in the while loop:

I want to use a while loop that basically does this: If the user entered anything else ( not Bitcoin or Chuck E Chesse), then tell the user to try again, and keep reading Strings until they enter a correct currency type. If the user 3 consecutive incorrect currency types, then exit the program.

Take a look at what I have so far.. when I run the program it does not quite do what I want it to do Also, there's something wrong with one of my if statements and I want to figure out how to fix it.

Java Code:

import java.util.Scanner;
public class CurrencyConverter
{
public static void main(String[] args)
{
System.out.println("----------------------------------");
System.out.println(" Currency Converter");
System.out.println("----------------------------------");

[Code]...

This is how I want my project to look like:

View Replies View Related

How To Get Overridden Currency Symbol From Windows

Jan 27, 2014

How in Java to get the current(overridden) currency symbol from the Windows?

As you know t is possible in Windows (Control Panel->Region->Additional Settings->Currency) change currency symbol to the new one.

For example default is '$' and customer change it to the '€'

And programs (Excel for example) use this new currency symbol, i.e instead of $100 you see €100.

I need emulate similar behavior in Java.

View Replies View Related

How To Get Overridden Currency Symbol From Windows

Jan 27, 2014

How in Java to get the current(overridden) currency symbol from the Windows?

As you know you able in Windows (Control Panel->Region->Additional Settings->Currency) change currency symbol to the new one.

And programs (Excel for example) use this new currency symbol.

I need emulate similar behavior in Java.

View Replies View Related

Billing Utility - Currency Symbol Format

May 19, 2014

package billing.util;
 
import java.math.RoundingMode;
import java.text.NumberFormat;
import java.util.Scanner;
public class CurrencyFormat {
private static final int USD = 0;
private static final int JPY = 1;
 
[Code] .....

i should be able to use USD, CNY, and JPY. However it seems only the USD ($) will run... doesnt matter which currency symbol the user requests.

View Replies View Related

Calculating Change In Denominations Of Currency Error

May 10, 2014

So I currently have working code that calculates the denominations that I need when change is displayed. The problem is that it seems to be missing one cents every time. So if my change prints out $12.35, it will end up being 1 - ten, 2 - ones, 1 - quarter, 1 - nickle, and 4 - pennies rather than 2 nickles. or 1 dime This happens for any dollar amount unless it is even cash and no change, or the change calculates to where there doesn't need to be a penny. Just an FYI, this code is being used in a GUI panel program if it seems strange in anyway.

int change1 = (int) ((total - realTotal)*100);
num100 = change1 / 10000;
change1 = change1 % 10000;
String dollar1;
dollar1 = String.valueOf(num100);

[code]....

View Replies View Related

Add Doubles In Array

Jan 20, 2014

I'm allowing the user to choose certain items to buy that is moved to an array.Now I'm trying to add those thing in the array use a different class. how I can call the array from my driver class to my checkout class that adds them together.

View Replies View Related

Scanner Isn't Accepting Doubles

Jan 25, 2014

I had to use scanner to receive input from the user for a formula and everything compiled and worked correctly except when I entered a double into the Scanner, it only accepts ints and gives me this error every time I enter a double:

java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextDouble(Unknown Source)
at TestA1Q2.main(TestA1Q2.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272)

I know that you usually get that error when the Scanner expects something else that is different from what you type and I have looked over my code time and time again and cannot find anything. I created a test program to see if it was just that problem and not something else in the code and I still got the same error but when I tried compiling and running it here browxy.com everything worked and I got the right answer for the formula. Here's the test I used:

import java.util.Scanner;
public class TestA1Q2 {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter a double");
double velocity = keyboard.nextDouble();
}
}

At this point I'm thinking it might be a problem with my install of DrJava and I've tried re-installing but nothing changed.

View Replies View Related

How To Add Doubles From A Text File

Apr 13, 2014

I have a text file that looks like this:

JacobAndrews8159RoseCtMill CityOR97322555212787964.00
RyanPerkins7546PrinceAveLas VegasNV87126555345198913.00
JoshuaGilbert9278MonroeDrCorvallisCA97330555283265695.00
MilesCrain4578ChesterDrCorvallisOR9733155523456781544.00
ButchCassidy5498SuttonPlGresham AZ9738054165657971798.56
PerryWinkle8185ShaverAveLas VegasNV871265553812346195.66

everything is separated by tabs.

My while loop is like this:

while(fileScan.hasNextLine()) {
String currentLine = fileScan.nextLine();
String[]dataSet = currentLine.split(" ");
String zip = dataSet[7];
String phone = dataSet[8];
String donation = dataSet[9];
int ZIP = Integer.parseInt(zip);
Double Donation = Double.parseDouble(donation);

As you can see I made the donation read as a double, my question is how do I get the donation total? I need to write the code to add up and get the total donations but cannot figure it out.

View Replies View Related

How To Work With Doubles In Arrays

Sep 13, 2014

import java.util.*;
public class OneDimenArray {
public static void main(String[] args) {
double[] decimals = new double[12];
double nums = 0.0;
double a = 1.0;
[Code] ....

These are the erroe codes I'm getting;

OneDimenArray.java:13: error: ']' expected
double[] decimals = double[Scanner.nextDouble()];
^
OneDimenArray.java:13: error: ';' expected
double[] decimals = double[Scanner.nextDouble()];
^
2 errors

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.

View Replies View Related

Set And Assign Doubles - String For Gross Pay?

Dec 15, 2014

I'm working with doubles I'm trying to figure out how to set this up so it works?

I'm just stuck on how to set and Assign a double FedTaxWitholding that gets the Fed Tax Withholding = Gross Pay * Fed
Tax Withholding Rate.

Do I need a string for Gross pay?

View Replies View Related

Java Program Using If / Else - Multiple Doubles

Oct 14, 2014

I am new to Java and I am having trouble figuring out why input.nextDouble(); is not working for the multiple doubles.

import java.util.Scanner;
public class SimpleMenu
{
public static void main(String [] args)
{
int userInput;
int input = 0;
double circleArea = 0;
double triangleArea = 0;
double rectangleArea = 0;

[Code] ....

View Replies View Related

JSF :: Append Dollar Symbol And Format Comma Of Currency Value In Input Text

Feb 17, 2014

I have a form with primefaces input text(p:inputText).Many of the input text values are of the type currency in dollars.When i try to use ,it mandates the user to include $ symbol prepended to the value.Is there any way using which on blur of the field the dollar symbol is prepended and the number gets formatted with proper commas.

View Replies View Related

Method That Returns Largest Value Of Array Of Doubles?

Jan 26, 2015

Write a Java method that returns the largest value of an array of doubles passed to the method as an argument.

Back into java wasn't sure how to do it for doubles did one in the main for integers and then added a method changed from int to double and now i'm lost as go why its not working.

package kickstarter9;
public class Kickstarter9 {
public static void main(String[] args){
double myList;
double[] myList = {6.0, 4.1, 2.4, 6.8, 1.9, 9.4, 2.8, 4.6, 9.3};
// find the largest value in the list

[Code]...

View Replies View Related

Infix To Prefix - Pow Only Takes Int Values Not Doubles

Feb 7, 2014

I am having a problem with infix and prefix ... Here is the code

import java.util.StringTokenizer;
import static java.lang.Math.pow;
import java.util.Stack;
 public class Calculator {
static int precedence(char op) {
switch(op) {

[Code] ....

it says in line 72
possible loss of precision
required: int
found: double
the pow only takes int values?not doubles?how do i fix it?

View Replies View Related

Return Smallest Of 10 Doubles (User Input)

Oct 1, 2014

This code will let a user type 10 double's, and return the smallest of those 10 double's. But I don't really understand what happens in de last for-loop.

package hsleiden.webcat.exercise06_09;
import java.util.Scanner;
public class Exercise06_09
{
public static void main (String[] args){
double[] allNumbers = new double [10];
 
[Code] ....

View Replies View Related

Swing/AWT/SWT :: Using Doubles For Positioning Objects And Testing Equality

Aug 15, 2014

I've been noticing some of my programs have been a little buggy recently, and think it's down to confusion over doubles and positioning. Lets say I have a label called banner that I want to scroll across the screen. Now I need to know the label's width in order to position it, but the width depends on the amount of text, so i use this code:

double bannerWidth = banner.getWidth();

Which forces me into using a double if I want to be accurate.

But the problem is that I'm trying to use a condition that compares the label's horizontal position (currentX) to the left edge of the screen (LEFT_EDGE), minus the width of the label (bannerWidth). In other words when the label is off the screen, it should go back to its starting position.

I assume that means that any variables I use to track the label's position (in this case currentX), or constants that I use to check equality (LEFT_EDGE), have to be doubles as well?

My difficulty is that I iterate currentX. But currentX--; won't work because doubles don't iterate as I'd expect.

So casting becomes an option..... but if I cast to an integer I effectively lose width on the label. And that is magnified each loop, resulting in the label's starting position moving further and further to the left.

View Replies View Related

Arithmetic Expression That Will Display Doubles To Only One Decimal Place?

Sep 29, 2014

I am looking to find a way to display the number of decimal places without using any type of formatting string.

Only to make it xxx.x instead of xxx.xxxxxx.

View Replies View Related

Formatting Doubles To Two Decimal Places Within Return Statement

Jan 25, 2015

I'm attempting to format my doubles to two decimal places within my return statement. I have tried to use DecimalFormat but it gives me an error because my method needs to return a double and that results in a string being returned. I have also tried using the *100.00/100.00 method and that doesn't work when the number already ends in 0.

If I pass -150.00 it gives me -150.0 when I need two decimal places.

How can I go about doing this?

View Replies View Related

Program To Store Total Rainfall For Each Of 12 Months Into Array Of Doubles

Oct 26, 2014

"Create a project called RainFall and a class nameD RainFall. Write a program that stores the total rainfall for each of 12 months into an array of doubles. The program should display total rainfall for the year, the average monthly rainfall, the month with the most rain and the month with the least rain. When outputting the month with the most and least rain, output the name of the month. This is what I have so far.

Scanner keyboard = new Scanner(System.in);
double averageMonthly;
double mostRain;
double leastRain;
int months;
double monthlyRain = 0;
double totalRain = 0;

[Code] ....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved