decimal

Problem to convert string binary (64 bits) to decimal (c++ in iphone)

Hi I have a problem converting a string binary to a decimal I was using bitset bitstring ="1011010001111111"; unsigned long binToDec( string bitstring){ bitset<32> dec (bitstring); return dec.to_ulong(); } All of this works fine, but !! the problem comes when i try to do the same with a bits string with more of 32 bits. I kn...

PHP: get number of decimal digits

Hi! Is there a straightforward way of determining the number of decimal places in a(n) integer/double value in PHP? (that is, without using explode) Thanks, Erwin ...

How can I use CodeDom to create a decimal constant?

I have this function in my generator. Private Sub AddBoundedValue(ByVal boundedValue As Object, ByVal type As CodeTypeDeclaration, ByVal numericType As Type, name As String) If boundedValue IsNot Nothing Then Dim constant As New CodeMemberField(numericType, name) constant.Attributes = MemberAttribut...

Converting a string to a mySql DECIMAL type

I am trying to insert data about an item's price from an HTML form into a mySQL database. The input field is defined as follows: <input type="text" name="price" value="0.00"/> The form is POSTed to the next page in which the database stuff is taken care of. Currently I just enter the exact contents of $_POST['price'] into the database...

Decimal Value is Zero when it should be 0.0x

If this was previously talked about, I'm sorry, I had a hard time searching on this. I am calculating a depreciation rate. One portion of our calculation is 1/life in months. My table stores this data in a decimal field. I tried test = 1 / estimatedLife; but the result of the calculation of test (which is defined as a decimal) is 0. S...

Rails: Cannot add :precision or :scale options with change_column in a migration?

This seems to have been asked before: http://stackoverflow.com/questions/1402547/rails-decimal-precision-and-scale But when running a change_column migration for :precision or :scale they don't actually affect the schema or database, but db:migrate runs without errors. My migration file looks like this: class ChangePrecisionAndScaleO...

Calculating pi using infinite series in C#

Hi! I tried to write the following program in C# to calculate pi using infinite recursion, but I keep getting confused about integer/double/decimal division. I really have no clue why this isn't working, so pardon me for my lack of understanding of strongly typed stuff, as I'm still learning C#. Thanks in advance! using System; using ...

How can I convert between scientific and decimal notation in Perl?

I know this is a total newbie question, but the answer may not be obvious to many new programmers. It wasn't initially obvious to me so I scoured the Internet looking for Perl modules to do this simple task. ...

If I divide 3 by 2 I want the answer to be 2 (ie 1.5 rounded to 2)

How to get he upper limit of a number in C? If I divide 3 by 2 I want the answer to be 2 (ie 1.5 rounded to 2). ...

Setting minimum number of decimal places for std::ostream precision

Hi, Is there a way to set the "minimum" number of decimal places that a std::ostream will output? For example, say I have two unknown double variables that I want to print (values added here for the sake of illustration): double a = 0; double b = 0.123456789; I can set my maximum decimal precision so that I output b exactly std::c...

nVelocity - Template issue when attempting 'greater than' comparison on decimal property

I have a simple object that has as one of it's properties a decimal named Amount. When I attempt a comparison on this property as part of an nVelocity template, the comparison always fails. If I change the property to be of type int the comparison works fine. Is there anything extra I need to add to the template for the comparison to wor...

Mysql issue with decimal

Hello, I have two fields - amount (decimal (11, 2)) - gift_amount (decimal (11, 2)) When I do an update on either for a value equal to or below 999.99, it saves correctly. However, if I go over that, then it drops the value right back to down 1 - 10. Is this a known issue or am I going wrong using decimal? Heres some PHP code of wh...

double to hex. How It's Made?

157,453796 = hex 18068A 157,455093 = hex 180697 71,5037 = hex E91D00 71,506104 = hex E93500 71,507103 = hex E93F00 0 = hex 000000 I know exactly what it is not IEEE 754 ...

Interconversion between decimal and any other base-n number system

Hello there, I have written some general functions to convert between decimal and any other base-n number system(n<=36 for now) and vice-versa. Don't want to make things messy here so i have posted the code here. Could anybody suggest any better way for this? May be more effective and Rubyish? Thanks ...

when you do decimals does the 0 go in front or back

when you are doing decimals does the 0 go in the front or back ...

Decimal type in Qt (C++)

What is the correct type to use in Qt development (or C++ in general) for decimal arithmetic, i.e. the equivalent of System.Decimal struct in .Net? Does Qt provide a built-in struct? (I can't find it in the docs, but maybe don't know where to look.) Is there a "standard" C++ library to use? ...

Decimal to binary (and vice-versa)

Can anybody give an example of c++ code that can easily convert a decimal value to binary and a binary value to decimal please? ...

Quoting of decimal values

I am storing a running total in a Decimal(10,2) field and adding to it as items are processed. update foo set bar = bar + '3.15' About 20% of the times a warning is issued "Data truncated for column 'bar' at row 4" This warning is never issued if the update value is not quoted. Should decimal values be quoted? ...

Python2.6 Decimal to Octal

How can i convert decimal to Octal in Python2.6, for 1 to 100000? I wanna get this converted result as .txt too. Can someone help me? ...

Hex to Decimal conversion in C

Hi All, Here is my code which is doing the conversion from hex to decimal. The hex values are stored in a unsigned char array: int liIndex ; long hexToDec ; unsigned char length[4]; for (liIndex = 0; liIndex < 4 ; liIndex++) { length[liIndex]= (unsigned char) *content; printf("\n Hex value is %.2x", length[liIn...