decimal

C program showing a square instead of string

I have done a lot with Java but I am currently trying to learn c. I am trying to make a program to convert a number from decimal to binary. Here is what I have: #include <stdio.h> #define LENGTH 33 int main( int argc, char*argv[ ] ) { unsigned int number, base, remainder, x, i; char result[LENGTH]; puts( "Enter a decimal value, a...

Math calculation with decimal isn't correct

I have a C# method and which accepts three string parameters. After converting them to decimal, I am trying to perform a simple math calculation. I don't understand, why isn't the result correct? decimal d = MyFunction(x, y, z); public decimal MyFunction(string x, string y, string z) { decimal dx = 0; decimal dy = 0; decim...

Is this SQL code susceptible to rounding errors?

I have discovered some strange behavior where a stored procedure is returning inaccurate results by a penny or two. Here's the code (I didn't write it): ALTER PROCEDURE [dbo].[TN_GetSimpleBalance] @custID int, @nBalance decimal (8,2) output AS declare @ArBalance as decimal (8,2) declare @custStatusCode varchar (2) declare @u...

What the best ways to use decimals and datetimes with protocol buffers?

I would like to find out what is the optimum way of storing some common data type that were not included in the list supported by protocol buffers. datetime (seconds precision) datetime (milliseconds precision) decimals with fixed precision decimals with variable precision lots of bool values (if you have lots of them it looks like you...

Converting Decimal to ASCII Character

I am trying to convert an decimal number to it's character equivalent. For example: int j = 65 // The character equivalent would be 'A'. Sorry, forgot to specify the language. I thought I did. I am using the Cocoa/Object-C. It is really frustrating. I have tried the following but it is still not converting correctly. char_num1 ...

Common lisp integer to hex conversion

Is there a similar function to (parse-integer "ff" :radix 16) that will take me back the other way? If I have the int 255 how do I convert it to the string ff? ...

Why does specifying a numeric value for a control's property in the designer result in new decimal(new int[] {... in the code?

In my C#.Net WinForm app in VS2005, I have a NumericUpDown control. In the designer, I set the Minimum property of the NumericUpDown to -65535. In the form's .designer.cs code, I expected to see this: this.myNumericUpDown.Minimum = -65535; but instead I get: this.myNumericUpDown.Minimum = new decimal(new int[] { 65535, 0...

How do I change my float into a two decimal number with a comma as a decimal point separator in python?

I have a float: 1.2333333 How do I change it into a two decimal number with a comma as a decimal point separator, eg 1,23? ...

Add a decimal point 2 chars from the right under PHP

I have a big array containing lots of elements containing numerical data. Example: 3200 34300 1499 12899 I want to convert these into: 32.00 343.00 14.99 128.99 How can I achieve this elegantly under PHP using no regex? Thanks in advance. ...

Android GPS Result Format

I have noticed with testing GPS locations, a value such as -123 might come up on Android as -123.83333336... is there anyway to format incoming GPS locations, such as within 2 decimal points? This way I can store values like -123.83 opposed to longer numeric values. I have checked out DecimalFormat and NumberFormat, these are strings and...

Conversion of a decimal to double number in C# results in a difference

Summary of the problem: For some decimal values, when we convert the type from decimal to double, a small fraction is added to the result. What makes it worse, is that there can be two "equal" decimal values that result in different double values when converted. Code sample: decimal dcm = 8224055000.0000000000m; // dcm = 8224055000 ...

Converting a decimal number into binary

I am currently reading Charles Petzold's book 'Code'. In it he explains how to convert a decimal number into binary using the following template: [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] ÷128 ÷64 ÷32 ÷16 ÷8 ÷4 ÷2 ÷1 [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] In th...

Python convert hex to float

How to convert the following hex string to float (single precision 32-bit) in python? "41973333" -> 1.88999996185302734375E1 "41995C29" -> 1.91700000762939453125E1 "470FC614" -> 3.6806078125E4 Thanks ...

php float calculation 2 decimal point

Hi everyone, Got another math calculation problem again. $a = 34.56 $b = 34.55 $a do some calculation to get this figure $b is doing rounding nearest 0.05 to get this figure what happen is $c = $b - $a supposedly I should be -0.01, but I echo out the $c is show -0.00988888888888 I try to use number_format($c, 2), but the output i...

converting binary to decimal in ocaml

How could I convert binary to decimal in ocaml in the following, If I am representing binary numbers like the following 01 is [False; True] which equals 2? I want to write a method to return the double of the number in decimal form. For example in this case the method will take in [False; True] and return [False; False, True] which is 4...

converting binary to decimal and decimal to binary in ocaml

How could I convert binary to decimal and decimal to binary in the following, If I am representing binary numbers like the following 01 is [False; True] which equals 2? I want to write a method to take in [False; True] and return 2. Also a method for doing it the other way around taking in an integer 2 and returning [False; True]. ...

ASP.NET/C# Decimal to 0.00

Hi i got this method, how can i make the decimal to .00 and not .0000 ? :) public static List<Product> GetAllProducts() { List<Product> products = new List<Product>(); string sqlQuery = "SELECT * FROM Products"; using (SqlConnection connection = new SqlConnection(connectionString)) { using (SqlCommand command...

How deal with the fact that most decimal fractions cannot be accurately represented in binary?

So, we know that fractions such as 0.1, cannot be accurately represented in binary base, which cause precise problems (such as mentioned here: http://stackoverflow.com/questions/1421520/formatting-doubles-for-output-in-c). And we know we have the decimal type for a decimal representation of numbers... but the problem is, a lot of Math m...

How to work around the decimal problem in JavaScript?

Possible Duplicates: Strange problem comparing floats in objective-C Is JavaScripts math broken? 1.265 * 10000 = 126499.99999999999 ????? After watching this I discovered that in JavaScript: 0.1 + 0.2 === 0.3 evaluates to false. Is there a way to work around this? ...

Why is System.Math and for example MathNet.Numerics based on double?

All the methods in System.Math takes double as parameters and returns parameters. The constants are also of type double. I checked out MathNet.Numerics, and the same seems to be the case there. Why is this? Especially for constants. Isn't decimal supposed to be more exact? Wouldn't that often be kind of useful when doing calculations? ...