decimal

How to take away fraction part from decimal?

How to take away fraction part while formatting decimal type in .NET? I need common syntax for both variants. Is there any gentle solution? decimal a = 1.22M; decimal b = 1.00M; String.Format("${0}", a); // result is $1.22 String.Format("${0}", b); // result is $1.00, should be $1, HOW? ...

How can i convert Integer value to decimal value?

Hi, i have an integer value Integer value = 56472201 ; (This could be some time (-17472201) with negetive Integer) I want this value in this form 56.472201 (i mean if i divide this value/1000000 i get it in general 56.472201) but this does not works in programming as it give the quotient. I want both quotient and remainder in thsi f...

How to truncate .000 zeros from double with NSNumberFormatter

Ok so if I have a double to begin with how do I limit it or truncate digits to 1dp since I know they're not needed to be viewed double a = 1.6; NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; NSString *numberAsString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:a]]; [numberFormatter setNumberSt...

How to export a c# decimal to a OLEDB Decimal(28,9) field

I'm approaching a access 2007 database using Microsoft.ACE.OLEDB.12.0. It contains a table created using CREATE TABLE reccs(decimalField decimal(28,9)) which has to have this precision and scale. I'm adding a row using string s = "INSERT INTO [reccs]([minQuantity]) VALUES(@minQuantity)"; object o = ...; oleDbCommand = new OleDbComm...

javascript floating decimal

I have a bit of javascript that dynamically multiplies what users are typing in a text field (by the base var), and displays it in a Now I'm just trying to figure out how to get the decimal places of the result to float to 2 places, i.e. 10.00 instead of 10 I found the toFixed function, but can't seem to use it properly... I'd appreciat...

Howto convert decimal (xx.xx) to binary

This isn't necessarily a programming question but i'm sure you folks know how to do it. How would i convert floating point numbers into binary. The number i am looking at is 27.625. 27 would be 11011, but what do i do with the .625? ...

Division by Zero Errors

Mann i have a problem with this question from my professor. Here is the question: Write the definition of a function typing_speed , that receives two parameters. The first is the number of words that a person has typed (an int greater than or equal to zero) in a particular time interval. The second is the length of the time interval i...

MySql decimal type display problem

Hi, I store money values in my db table. E.g. I have 2.50. But when I print that value the 0 is always missing so I get 2.5. The db table money field has the following type: decimal(6,2) any idea how to fix that? ...

MVC 2, Format Model display into a textbox

I have an easy one for you guys. In my view I have a textbox, like so: <%= Html.TextBoxFor(x => x.Price, new { @class = "text tiny" })%> Price is a decimal. When the form loads up. the textbox displays "0". I would like it to display "0.00". I tried <%= Html.TextBoxFor(x => String.Format("{0:0.00}", x.Price), new { @class = "text ...

How do I round down a decimal to 2 decimal places in .Net?

This should be easy, but I can’t find a built in method for it, the .net framework must have a method to do this! private decimal RoundDownTo2DecimalPlaces(decimal input) { if (input < 0) { throw new Exception("not tested with negitive numbers"); } // There must be a better way! return Math.Truncate(input * 100) / ...

Is working with money (decimal numbers) in PHP considered safe?

I have an items table in my MySQL database with a DECIMAL(10,2) field called price. When fetching these values, is it safe to do calculations and such with these numbers in PHP? Or will I end up with potential rounding errors and things like that which are common when working with floating point data types? How does PHP handle these th...

Query number of decimal places in a sql server resultset

I have a table which contains a field of type numeric(28,10). I would like to display the records with a monospaced font, and a matching number of decimal places so that they line up when right aligned. Is there any way to figure out the maximum number of decimal places that can be found in a given result set so that I can format accor...

how to read a sqlite3 decimal column?

I can read a text and an int column (sqlite3_column_text, sqlite3_column_int). But does anyone know how to read in a sqlite decimal column? The decimal columns essentially hold currency values. Thanks! ...

Binary representation of a .NET Decimal

Hey all, quick question: How does a .NET decimal type get represented in binary in memory? We all know how floating-point numbers are stored and the thusly the reasons for the inaccuracy thereof, but I can't find any information about decimal except the following: Apparently more accurate than floating-point numbers Takes 128 bits of...

Keypad decimal separator on a Wpf TextBox, how to?

I have a Wpf application with some textbox for decimal input. I would that when I press "dot" key (.) on numeric keypad of pc keyboard it send the correct decimal separator. For example, on Italian language the decimal separator is "comma" (,)...Is possible set the "dot" key to send the "comma" character when pressed? ...

Best practice for working with currency values in PHP?

I need to add, multiply and compare currency values in PHP and need to be sure that it is exact down to a single cent. One way is to store everything in float, use round before and after each operation and mind machine epsilon when comparing for equality. Quite cumbersome imho. Another way is to store the whole thing as cents in intege...

Decimal to floating point

If I wanted to convert a number Ex. 32.24x10^5 to IEEE 754 standard BY HAND how would I do it? ...

A better Ruby implementation of round decimal to nearest 0.5

This seems horrible inefficient. Can someone give me a better Ruby way. def round_value x = (self.value*10).round/10.0 # rounds to two decimal places r = x.modulo(x.floor) # finds remainder f = x.floor self.value = case when r.between?(0, 0.25) f when r.between?(0.26, 0.75) f+0.5 when r.between?(0.76, 0.99) f+...

Convert a double to fixed decimal point in C++

I have a double variable in C++ and want to print it out to the screen as a fixed decimal point number. Basically I want to know how to write a function that takes a double and a number of decimal places and prints out the number to that number of decimal places, zero padding if necessary. For example: convert(1.235, 2) would print ...

Python - question about decimal arithmetic

I have 3 questions pertaining to decimal arithmetic in Python, all 3 of which are best asked inline: 1) >>> from decimal import getcontext, Decimal >>> getcontext().prec = 6 >>> Decimal('50.567898491579878') * 1 Decimal('50.5679') >>> # How is this a precision of 6? If the decimal counts whole numbers as >>> # part of the precision, is...