Search Results

Search found 1193 results on 48 pages for 'decimal'.

Page 8/48 | < Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >

  • Trouble calculating correct decimal digits.

    - by Crath
    I am trying to create a program that will do some simple calculations, but am having trouble with the program not doing the correct math, or placing the decimal correctly, or something. Some other people I asked cannot figure it out either. Here is the code: http://pastie.org/887352 When you enter the following data: Weekly Wage: 500 Raise: 3 Years Employed: 8 It outputs the following data: Year Annual Salary 1 $26000.00 2 $26780.00 3 $27560.00 4 $28340.00 5 $29120.00 6 $29900.00 7 $30680.00 8 $31460.00 And it should be outputting: Year Annual Salary 1 $26000.00 2 $26780.00 3 $27583.40 4 $28410.90 5 $29263.23 6 $30141.13 7 $31045.36 8 $31976.72 Here is the full description of the task: 8.17 ( Pay Raise Calculator Application) Develop an application that computes the amount of money an employee makes each year over a user- specified number of years. Assume the employee receives a pay raise once every year. The user specifies in the application the initial weekly salary, the amount of the raise (in percent per year) and the number of years for which the amounts earned will be calculated. The application should run as shown in Fig. 8.22. in your text. (fig 8.22 is the output i posted above as what my program should be posting) Opening the template source code file. Open the PayRaise.cpp file in your text editor or IDE. Defining variables and prompting the user for input. To store the raise percentage and years of employment that the user inputs, define int variables rate and years, in main after line 12. Also define double variable wage to store the user’s annual wage. Then, insert statements that prompt the user for the raise percentage, years of employment and starting weekly wage. Store the values typed at the keyboard in the rate, years and wage variables, respectively. To find the annual wage, multiply the new wage by 52 (the number of weeks per year) and store the result in wage. Displaying a table header and formatting output. Use the left and setw stream manipulators to display a table header as shown in Fig. 8.22 in your text. The first column should be six characters wide. Then use the fixed and setprecision stream manipulators to format floating- point values with two positions to the left of the decimal point. Writing a for statement header. Insert a for statement. Before the first semicolon in the for statement header, define and initialize the variable counter to 1. Before the second semicolon, enter a loop- continuation condition that will cause the for statement to loop until counter has reached the number of years entered. After the second semicolon, enter the increment of counter so that the for statement executes once for each number of years. Calculating the pay raise. In the body of the for statement, display the value of counter in the first column and the value of wage in the second column. Then calculate the new weekly wage for the following year, and store the resulting value in the wage variable. To do this, add 1 to the percentage increase (be sure to divide the percentage by 100.0 ) and multiply the result by the current value in wage. Save, compile and run the application. Input a raise percentage and a number of years for the wage increase. View the results to ensure that the correct years are displayed and that the future wage results are correct. Close the Command Prompt window. We can not figure it out! Any help would be greatly appreciated, thanks!

    Read the article

  • Calculate pi to an accuracy of 5 decimal places?

    - by pgras
    In this message at point 18 I saw following programming question: Given that Pi can be estimated using the function 4 * (1 – 1/3 + 1/5 – 1/7 + …) with more terms giving greater accuracy, write a function that calculates Pi to an accuracy of 5 decimal places. So I know how to implement the given function and how to choose how "far" I should calculate, but how can I tell when I've reached the "accuracy of 5 decimal places" ?

    Read the article

  • Convert an array of bytes into one decimal number as a string

    - by Martin Kirsche
    I'm trying to write function that converts an arbitrary large array of bytes (larger than 64-bit) into a decimal number represented as string in c# and I simply can't figure out how to do it. For example the following code ... Console.WriteLine(ConvertToString( new byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00 })); .. should print out 22774453838368691933757882222884355840 I don't want to just use an extra library like biginteger for that, because I want it to be simple and like to understand how it works.

    Read the article

  • Handling Datetime with decimal '2010-02-14 20:18:58.313000000'

    - by AaronLS
    In SQL Server I have some textual data in varchar fields I am trying to convert to datetime's. The funny thing is this data at some point was in a datetime field, exported to flat file, and now I am reimporting it. The problem is it is in this format 2010-02-14 20:18:58.313000000 and the conversion to datetime fails. I have no idea how it ended up like this when it was originally extracted from a datetime column. Basically a table was exported to a flat file by someone else. The original table was lost. I am reimporting back from the flatfile. I could just drop the decimal but this would be like throwing out some of the data. I'd like to maintain as much precision as possible. How can I import this data from the varchar column back into a datetime column and preserve as much accuracy as possible?

    Read the article

  • Databinding to type double - decimal mark lost

    - by user1277327
    I have a project where I'm databinding a gridview to a list, where one column is databound to a gridview. The problem I have is that with the double being 5.5 on one computer it appears as 5.5 in the gridview. But on another it looks like 55, the decimal mark dissapears. So 3.14 will look like 314 etc. The error occurs with the following code: myDatagrid.ItemsSource = someList; Binding binding = new Binding("DoubleValue"); myColumnInDatagrid.Binding = binding; I've also tried using a very simple valueconverter, that just return the double, and parsed it in ConvertBack. I'm pretty new to WPF so I'm sorry if I've made some obvious mistakes, I just don't understand why it works on one computer but not on the other. Perhaps it should be noted that both of the computers use the same operating system, with the same language settings (afaik at least).

    Read the article

  • Deciphering a queer compiler warning about unsigned decimal constant

    - by Artagnon
    This large application has a memory pool library which uses a treap internally to store nodes of memory. The treap is implemented using cpp macros, and the complete file trp.h can be found here. I get the following compiler warning when I attempt to compile the application: warning: this decimal constant is unsigned only in ISO C90 By deleting portions of the macro code and using trial-and-error, I finally found the culprit: #define trp_prio_get(a_type, a_field, a_node) \ (2654435761*(uint32_t)(uintptr_t)(a_node)) I'm not sure what that strange number is doing there, but I assume it's there for a good reason, so I just want to leave it alone. I do want to fix the warning though- any idea why the compiler's saying that it's unsigned only in ISO C90? EDIT: I'm using gcc-4.1

    Read the article

  • excel number format - varying decimal digits

    - by Alexxx
    I'm trying to set a special cell number format with theses rules: display percentage display at max 3 digits (decimal + integer part) So I can display 100% or 99.3% or 1.27% but not 100.9% or 100.27% or 99.27%. Of course, I can have negative number (-27.3%) and it does not affect my rules. I've try with the cell formating option without success: [<1]0.00%;[<10]0.0%;0% Because it seemed that excel (2010) does not support more than 2 conditions in cell formating (and so I can't expand it to manage negative number...) It there anyway to do what I want? Thanks

    Read the article

  • Validate decimal number in (known) national format

    - by Álvaro G. Vicario
    PHP has many built-in functions to validate numbers but they all expect input in computer format: 1234.56. I need to validate stuff like 1,234.56 (English) or 1.234,56 (Spanish), together with some typical attributes (accepted range, max number of decimals, etc.). I started writing my own function but I soon got lost. It's easy to read the user input into a float variable but I want to be able to detect numbers with invalid formats like 1,23456.7 or 1..25. Do you have any recommendation on the subject? (Decimal and thousand characters are known beforehand and it's okay to hard-code digit groups as three, there's no need to cover Indian number format.)

    Read the article

  • C++ converting hexadecimal md5 hash to decimal integer

    - by Zackery
    I'm doing Elgamal Signature Scheme and I need to use the decimal hash value from the message to compute S for signature generation. string hash = md5(message); cout << hash << endl; NTL::ZZ msgHash = strtol(hash.c_str(), NULL, 16); cout << msgHash << endl; There are no integer large enough to contain the value of 32 byte hexadecimal hash, and so I tried big integer from NTL library but it didn't work out because you cannot assign long integer to NTL::ZZ type. Is there any good solution to this? I'm doing this with visual C++ in Visual Studio 2013.

    Read the article

  • Converting binary to hexadecimal??

    - by Bobbert
    Hey guys, Just wondering on how I would go about converting binary to hexadecimal?? Would I first have to convert the binary to decimal and then to hexadecimal?? For example, 101101001.101110101010011 How would I go about converting a complex binary such as the above to hexadecimal? Thanks in advance

    Read the article

  • Converting to Base 10

    - by incrediman
    Hi, Let's say I have a string or array which represents a number in base N, N1, where N is a power of 2. Assume the number being represented is larger than the system can handle as an actual number (an int or a double etc). How can I convert that to a decimal string? I'm open to a solution for any base N which satisfies the above criteria (binary, hex, ...).

    Read the article

  • Dividing into fractors in C#

    - by Shane
    Simple question I think, I am a little unsure as to why decimal currentPercentage = 0; currentPercentage = currentPercentage*((decimal)1 / (decimal)daysPerYear--);//or currentPercentage *= ((decimal)1 / (decimal)daysPerYear--); Will return 0 everytime but (decimal)1 / (decimal)daysPerYear--; will return the decimal I am after. What am I missing here?

    Read the article

  • Why does isNaN(123.) return false?

    - by vivekraman
    Hi, Why does the Javascript function call isNaN(123.) return false? Is this a universally acceptable number or will it cause errors downstream? I'm validating whether a value is a valid decimal using isNaN along with split. Are there cross-browser issues with isNaN? Should I use a bespoke implementation? Thanks.

    Read the article

  • Problem with Informix JDBC, MONEY and decimal separator in string literals

    - by Michal Niklas
    I have problem with JDBC application that uses MONEY data type. When I insert into MONEY column: insert into _money_test (amt) values ('123.45') I got exception: Character to numeric conversion error The same SQL works from native Windows application using ODBC driver. I live in Poland and have Polish locale and in my country comma separates decimal part of number, so I tried: insert into _money_test (amt) values ('123,45') And it worked. I checked that in PreparedStatement I must use dot separator: 123.45. And of course I can use: insert into _money_test (amt) values (123.45) But some code is "general", it imports data from csv file and it was safe to put number into string literal. How to force JDBC to use DBMONEY (or simply dot) in literals? My workstation is WinXP. I have ODBC and JDBC Informix client in version 3.50 TC5/JC5. I have set DBMONEY to just dot: DBMONEY=. EDIT: Test code in Jython: import sys import traceback from java.sql import DriverManager from java.lang import Class Class.forName("com.informix.jdbc.IfxDriver") QUERY = "insert into _money_test (amt) values ('123.45')" def test_money(driver, db_url, usr, passwd): try: print("\n\n%s\n--------------" % (driver)) db = DriverManager.getConnection(db_url, usr, passwd) c = db.createStatement() c.execute("delete from _money_test") c.execute(QUERY) rs = c.executeQuery("select amt from _money_test") while (rs.next()): print('[%s]' % (rs.getString(1))) rs.close() c.close() db.close() except: print("there were errors!") s = traceback.format_exc() sys.stderr.write("%s\n" % (s)) print(QUERY) test_money("com.informix.jdbc.IfxDriver", 'jdbc:informix-sqli://169.0.1.225:9088/test:informixserver=ol_225;DB_LOCALE=pl_PL.CP1250;CLIENT_LOCALE=pl_PL.CP1250;charSet=CP1250', 'informix', 'passwd') test_money("sun.jdbc.odbc.JdbcOdbcDriver", 'jdbc:odbc:test', 'informix', 'passwd') Results when I run money literal with dot and comma: C:\db_examples>jython ifx_jdbc_money.py insert into _money_test (amt) values ('123,45') com.informix.jdbc.IfxDriver -------------- [123.45] sun.jdbc.odbc.JdbcOdbcDriver -------------- there were errors! Traceback (most recent call last): File "ifx_jdbc_money.py", line 16, in test_money c.execute(QUERY) SQLException: java.sql.SQLException: [Informix][Informix ODBC Driver][Informix]Character to numeric conversion error C:\db_examples>jython ifx_jdbc_money.py insert into _money_test (amt) values ('123.45') com.informix.jdbc.IfxDriver -------------- there were errors! Traceback (most recent call last): File "ifx_jdbc_money.py", line 16, in test_money c.execute(QUERY) SQLException: java.sql.SQLException: Character to numeric conversion error sun.jdbc.odbc.JdbcOdbcDriver -------------- [123.45]

    Read the article

  • [C#] Convert string to double with 2 digit after decimal separator

    - by st.stoqnov
    All began with these simple lines of code: string s = "16.9"; double d = Convert.ToDouble(s); d*=100; The result should be 1690.0, but it's not. d is equal to 1689.9999999999998. All I want to do is to round a double to value with 2 digit after decimal separator. Here is my function. private double RoundFloat(double Value) { float sign = (Value < 0) ? -0.01f : 0.01f; if (Math.Abs(Value) < 0.00001) Value = 0; string SVal = Value.ToString(); string DecimalSeparator = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator; int i = SVal.IndexOf(DecimalSeparator); if (i > 0) { int SRnd; try { // ????? ??????? ????? ???? ?????????? ?????????? SRnd = Convert.ToInt32(SVal.Substring(i + 3, 1)); } catch { SRnd = 0; } if (SVal.Length > i + 3) SVal = SVal.Substring(0, i + 3); //SVal += "00001"; try { double result = (SRnd >= 5) ? Convert.ToDouble(SVal) + sign : Convert.ToDouble(SVal); //result = Math.Round(result, 2); return result; } catch { return 0; } } else { return Value; } But again the same problem, converting from string to double is not working as I want. A workaround to this problem is to concatenate "00001" to the string and then use the Math.Round function (commented in the example above). This double value multiplied to 100 (as integer) is send to a device (cash register) and this values must be correct. I am using VS2005 + .NET CF 2.0 Is there another more "elegant" solution, I am not happy with this one.

    Read the article

  • How to do number formatting to 1 decimal point in SSRS?

    - by san
    Hi, I have a SSRS report with full of number fields. I would like to have that to be displayed as in one decimal. i tried to use F1. it gives me only one decimal points in html rendering, but in excel exported version it shows 2 decimal points. How can i have just one decimal point both ecxel and html rendering. Please comment. Thanks in advance San

    Read the article

  • Why do I need an intermediate conversion to go from struct to decimal, but not struct to int?

    - by Jesse McGrew
    I have a struct like this, with an explicit conversion to float: struct TwFix32 { public static explicit operator float(TwFix32 x) { ... } } I can convert a TwFix32 to int with a single explicit cast: (int)fix32 But to convert it to decimal, I have to use two casts: (decimal)(float)fix32 There is no implicit conversion from float to either int or decimal. Why does the compiler let me omit the intermediate cast to float when I'm going to int, but not when I'm going to decimal?

    Read the article

  • Android: Calculator on showing 0 immediately after the dot

    - by pearmak
    I am now working on a calculator, and everything works fine except for decimal places. The calculator contains 2 displays actually, one is called fakedisplay for actual operations, and one is called Display, for presenting the desired format, ie adding commas. When pressing 12345.678, Display will follow fakedisplay and present as 12,345.678, but if i press 12345.009, the fakedisplay will work normally as 12345.009, but the Display stuck as 12,345 until 9 is pressed, and at that time it will show 12,345.009 normally. However, it is strange that when the user presses 0, there is no response, and until pressing 9, 009 will then immediately append. I know this arise from the parsing code, but based on this, how could I amend the following code? I really cannot think of any solution... Many thanks for all your advice! one.setOnClickListener(new View.OnClickListener() { if (str.length()<15) {Fakedisplay.append("1");} DecimalFormat myFormatter1 = new DecimalFormat("###,###,###,###.#################"); String str1=Fakedisplay.getText().toString(); String stripped1 = Double.valueOf(str1).toString(); stripped1 = myFormatter1.format(Double.valueOf(stripped1)); if (stripped1.endsWith(".0")) stripped1 = stripped1.substring(0, stripped1.length() - 2); Display.setText(stripped1);

    Read the article

  • Why don't computers store decimal numbers as a second whole number?

    - by SomeKittens
    Computers have trouble storing fractional numbers where the denominator is something other than a solution to 2^x. This is because the first digit after the decimal is worth 1/2, the second 1/4 (or 1/(2^1) and 1/(2^2)) etc. Why deal with all sorts of rounding errors when the computer could have just stored the decimal part of the number as another whole number (which is therefore accurate?) The only thing I can think of is dealing with repeating decimals (in base 10), but there could have been an edge solution to that (like we currently have with infinity).

    Read the article

  • Decimal point issue on cocoa app

    - by Manuel Rocha
    I there, I'm trying making my first cocoa app, but I'm having problems with float numbers because of the regional settings. If I write on the TextBox the float number 1.2 I only can get the number 1, but If I write on the same TextBox the same float number but this time with the ',' sign instead (1,2) I can get the right float value. How can I bypass the regional settings? Kind Regards, Manuel Rocha

    Read the article

  • Using NSNumberFormatter to get a decimal value from an international currency string

    - by Duncan A
    It seems that the NSNumberFormatter can't parse Euro (and probably other) currency strings into a numerical type. Can someone please prove me wrong. I'm attempting to use the following to get a numeric amount from a currency string: NSNumberFormatter *currencyFormatter = [[[NSNumberFormatter alloc] init] autorelease]; [currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; NSNumber *currencyNumber = [currencyFormatter numberFromString:currencyString]; This works fine for UK and US currency amounts. It even deals with $ and £ and thousands separators with no problems. However, when I use it with euro currency amounts (with the Region Format set to France or Germany in the settings app) it returns an empty string. All of the following strings fail: 12,34 € 12,34 12.345,67 € 12.345,67 It's worth noting that these strings match exactly what comes out of the NSNumberFormatter's stringFromNumber method when using the corresponding locale. Setting the Region Format to France in the settings app, then setting currencyNumber to 12.34 in the following code, results in currencyString being set to '12,34 €' : NSNumberFormatter *currencyFormatter = [[[NSNumberFormatter alloc] init] autorelease]; [currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; NSString *currencyString = [currencyFormatter stringFromNumber:currencyNumber]; It would obviously be fairly easy to hack around this problem specifically for the Euro but I'm hoping to sell this app in as many countries as possible and I'm thinking that a similar situation is bound to occur with other locales. Does anyone have an answer? TIA, Duncan

    Read the article

  • jquery input-validation (number characters and decimal places).

    - by Cesar Lopez
    I have several javascript functions to validate the input data in textbox, so it will limit the user to type into the textbox a range of numbers (eg. from 0 to 500) an x amount of decimals (eg. 1 or 2 or 3 ....). I am having some issues with the javascript functions because they are three separate functions and the alerts get a bit mixed up. I was wondering if there is a jquery function that will make it neat, effective and simple. Thanks.

    Read the article

< Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >