decimal

Decimal data Type Display scale part as zero

I have Decimal field in SQLserver 2005 table, Price decimal(18, 4) if I write 12 it will be converted to 12.0000, if I write 12.33 it will be converted into 12.3300. Always it's putting zero to the right of the decimal point in the count of Scale Part(4). I was using these in SQL Server 2000, it was not behaving like this, i...

getting Ceil() of Decimal in python?

Is there a way to get the ceil of a high precision Decimal in python? >>> import decimal; >>> decimal.Decimal(800000000000000000001)/100000000000000000000 Decimal('8.00000000000000000001') >>> math.ceil(decimal.Decimal(800000000000000000001)/100000000000000000000) 8.0 math rounds the value and returns non precise value ...

How would I convert decimal into binary?

All I really know is PHP and I used the decbin function etc, It was fairly easy to do. In this C++ program I want to do the same thing, just a simple number or string how would I do this? ...

Dropping the '.00' when printing floats that hold whole numbers

I'm currently displaying a quantity in Javascript. I want it to display (for example) the whole number as 89 instead of 89.00; however, if the number is fractional like 89.50 then it should display 89.50 ...

How do I convert decimal numbers to binary in Perl?

I am trying to make a program that converts decimal numbers or text into binary numbers in perl. The program asks for user input of a character or string , and then prints out the result to the console. How do I do this? My code I have been working on is below, but i cannot seem to fix it. print "Enter a number to convert: "; chomp($dec...

Round a decimal to the nearest quarter in C#

Hello, Is there a simple way in c# to round a decimal to the nearest quarter i.e. x.0, x.25, x.50 x.75 for example 0.21 would round to 0.25, 5.03 would round to 5.0 Thanks in advance for any help. ...

Python's behavior for rich comparison (Or, when Decimal('100.0') < .01)

So I have a one liner: import decimal; h = decimal.Decimal('100.0'); (h > .01, h < .01, h.__gt__(.01), h.__lt__(.01)) All it does is make a Decimal object holding 100.0, and compares it to .01 (the float) in various ways. My result is: >>> import decimal; h = decimal.Decimal('100.0'); (h > .01, h < .01, h.__gt__(.01), h.__lt__(.01))...

Working with decimal numbers in PHP

I want to somehow round the numbers for a rating system in PHP like this: 4.6667 = 4.6 5.0001 = 5.0 Is there any way to do that? (BTW, I read the data from a database.) ...

How to maintain decimal precision in calculations

I need to sum 2 decimal values together, then divide by 2 and convert to string. My calculation currently is trimming to 2 decimal places, but I want to keep as many decimals as I can. city.Latitude = ( (lat.North + lat.South) / 2 ).ToString(); the values for lat.North and lat.South are like: 55.32342322 ...

Good way to format decimal in SQL Server

We store a decimal(9,8) in our database. It can have any number of places after the decimal point (well, no more than 8). I am frustrated because I want to display it as human-readable text as part of a larger string created on the server. I want as many decimals to the right of the decimal point as are non-zero, for example: 0.05 0....

ActiveScaffold keeps rounding my numbers

I need to display & edit highly precise decimal numbers - latitude and longitude. ActiveScaffold keep rounding my values to precision 6 scale 3, can I change that to precision 11 scale 8 somewhere? Thanks ...

C# decimal places with integer operators

So I have this code: p.Value = 1; decimal avg = p.Value * 100 / 10000; string prntout = p.Key + " : " + avg.ToString(); Console.WriteLine(prntout); But the program prints out 0, instead of 0.01. p.Value is an int. How do I fix that? ...

Precise Financial Calculation in JavaScript. What Are the Gotchas?

In the interest of creating cross-platform code, I'd like to develop a simple financial application in JavaScript. The calculations required involve compound interest and relatively long decimal numbers. I'd like to know what mistakes to avoid when using JavaScript to do this type of math—if it is possible at all! ...

PHP/MySQL won't update decimal field

I have this query: UPDATE table_name SET field_1 = field_1 +100, field_2 = field_2 +100, field_3 = field_3 +100 WHERE id = 1 LIMIT 1; Where Field_1 is regular integer, Field_2 is decimal(15,6) and Field_3 is double(15,6). When I run this query from php script they update just field_1 and nothing happen with field_2 an...

convert float numbers to hex

I am quite new in Python and I am looking for converting numbers from decimal to hex How to convert float numbers to hex or char in Python 2.4.3? how can I keep it to write it as ("\xa5\x (here the new hex number)") any help Thanks, ...

How to fix issue with decimal values in Sybase ODBC driver using NHibernate?

Sybase ODBC driver have an issue with the decimal data type. For example, when an application is trying to save in the database a decimal value occurs this error: ERROR [22018] [DataDirect][ODBC Sybase Wire Protocol driver][SQL Server]Implicit conversion from datatype 'VARCHAR' to 'DECIMAL' is not allowed. Use the CONVERT function to...

Is using decimal ranges in a switch impossible in C#?

I'm just starting out learning C# and I've become stuck at something very basic. For my first "app" I thought I'd go for something simple, so I decided for a BMI calculator. The BMI is calculated into a decimal type which I'm now trying to use in a switch statement, but aparently decimal can't be used in a switch? What would be the C...

Remove trailing zeros from decimal in SQL Server

I have a column DECIMAL(9,6) i.e. it supports values like 999,123456. But when I insert data like 123,4567 it becomes 123,456700 How to remove those zeros? ...

Decoding Decimal64 data

I'm looking for a simple way to decode data stored in the Decimal64 format (described here: http://en.wikipedia.org/wiki/Decimal64_floating-point_format) using C#. Any thoughts? ...

0.699 x 100 = 69.89999999999999 ?

Possible Duplicates: Why does 99.99 / 100 = 0.9998999999999999 Dealing with accuracy problems in floating-point numbers I've seen this issue in php and javascript. I have this number: float 0.699 if I do this: 0.699 x 100 = 69.89999999999999 why? edit round(0.699 x 10, 2): float 69.90000000000001 ...