473,881 Members | 1,616 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

very simple question, regarding maths in java

9 New Member
Hi, i am just starting to learn javascript, so i am probably doing something very simple wrong. i have read a lot of articles on maths in java, but cant find anything simple enough for my problem. I am looking for how to get an IF statement to give me the correct output. I am trying to get it to give me a result for a weeks pay, taking that the code worked before i tried to add the IF statement, to make it that if HoursWorked >= 20, the rate of pay would be an extra $2 p/hr. i had the following code to make this work

Expand|Select|Wrap|Line Numbers
  1. if (HoursWorked >= 20)
  2. {
  3.   WeeksPay = parseFloat(HoursWorked) * parseFloat(RateOfPay + 2);
  4. }
  5. else
  6. {
  7.   WeeksPay = parseFloat(HoursWorked) * parseFloat(RateOfPay);
but, as simple maths will tell you, the answer is not $3800!! can anyone please tel me what silly mistake i am making here please :) sorry to be asking something so simple, but my teacher is away for the weekend and i have just started this module in my course.
Nov 6 '09 #1
5 1766
13,262 MVP
Java != Javascript.
I'll assume you meant what you said when you said javascript so I'll move this to the Javascript forum.
Nov 6 '09 #2
8,658 Recognized Expert Moderator Expert
what are the HoursWorked and RateOfPay values, before the calculation?
Nov 7 '09 #3
9 New Member
Expand|Select|Wrap|Line Numbers
  1. HoursWorked=prompt("How many hours did you work this week?","25");
  2. RateOfPay=prompt("How much are you paid per Hour?","15")
i dont even know how it is getting the result it is, 3800... all the other tasks i have been doing have been working fine, even the more complicated ones.
Nov 7 '09 #4
8,658 Recognized Expert Moderator Expert
that explains it…
Expand|Select|Wrap|Line Numbers
  1. parseFloat(RateOfPay + 2)
the + operator does not only adds numbers, it also concatenates strings. and that’s what’s happening.

better use
Expand|Select|Wrap|Line Numbers
  1. parseFloat(RateOfPay) + 2
Nov 7 '09 #5
9 New Member
thankyou so much! it works fine now :)
Nov 7 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

by: LJL | last post by:
Greetings: I have a question regarding the system time and Netscape 7. I am running Win98SE. When Netscape 7 first loads it seems to store the currently set system time zone information. If I change the time zone after Netscape 7 is loaded, from Eastern time to Pacific time for example, it still uses the old time zone info. In other words, the system clock now says it is Pacific time but Netscape still reports Eastern time if it is...
by: WindAndWaves | last post by:
Hi there I have $initstartdate = date("d-m-Y"); in my code How can I get it to be date() + 1 or 7 for that matter. Because my server is in the US and I am in New Zealand, they are always a day behind....
by: Lee David | last post by:
I went to the sun site and downloaded what I hope is the development part of java. I downloaded JDK5 with Netbeans. I installed it and now have a folder in my program group "Netbeans". Is that java? Would I execute that to create a java application? TIA, Lee
by: Patrick.O.Ige | last post by:
I have an sample xml below. I want to do a distinct on the code node and the programDescription. I want the output to be like in a tree structure. So i would like to have PRG004 >Crazy Training 2> MAT01 PHS101 Any ideas it musn't be in a tree but it could be in a table structure Thanks <?xml version="1.0" standalone="yes"?>
by: Rote Rote | last post by:
I have an sample xml below. I want to do a distinct on the code node and the programDescription. I want the output to be like in a tree structure. So i would like to have PRG004 >Crazy Training 2> MAT01 PHS101 Any ideas it musn't be in a tree but it could be in a table structure Thanks <?xml version="1.0" standalone="yes"?>
by: Patrick.O.Ige | last post by:
I have a xml file and i want to format it using XSL I needed to do a distinct which is ok on the first node "Code" But when it gets to the "programDescription" node it prints out values for both Code="PRG004" and PRG005 which is CrazyTraining 2 and Program6 I want CrazyTraining 2 for PRG004 and Program6 for PRG005 Any help? Thx
by: Knut Olsen-Solberg | last post by:
I try to change the text in a <p> using getElementById(). I wonder what properties exists, and which one to use here. (The following does not work.) Regards Knut ______________________ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <TITLE>JavaScript</TITLE>
by: rob | last post by:
Hi everyone, Hope someone can give me a clear answer: which way I can go to run asp on apache solaris server? Thanks, Robert
by: stdlib99 | last post by:
Hi, I have a simple question regarding templates and meta programming. I am going to try and work my way through the C++ Template Metaprogramming, a book by David Abrahams and Aleksey Gurtovoy. I’m not doing this because I want to be a Meta Programming guru (because a lot of that stuff looks too crazy for use in the real world). Rather I want to learn heavyweight templates and this is the only
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.