decimal

PHP: need more decimal places for sinus calculation

Hi volks, to calculate some longitude and latitude values I need more decimal places like mysql is possible to do. For instance with mysql I get this result: cos( RADIANS( 47.685618 ) ) = 0.67319814951254 With PHP 5.2 I only get: cos( deg2rad( 47.685618 ) ) = 0.673198149513 Two decimal places shorter but I need them. I know I a...

Procedure in converting int to decimal data type?

I have an int(11) column which is used to store money. I read some of the answers on SO and it seems I just need to update it to be a decimal (19,4) data type. Are there any gotchas I should know about before I actually do the converting? My application is in PHP/Zend and I'm not using an ORM so I doubt I would need to update any sort o...

Are there any common gotchas with using decimal as opposed to double in MySQL?

A friend of mine said that they experienced oddities with using the decimal column to store money formats such as saving 1000.00 which would result in it being stored as 999.99. However I just tested and 1000.00 is stored as 1000.0000 on decimal(19,4) / MySQL 5. Can anyone offer insight into why they may have experienced issues? Perhaps...

Why does a C# System.Decimal remember trailing zeros?

Is there a reason that a C# System.Decimal remembers the number of trailing zeros it was entered with? See the following example: public void DoSomething() { decimal dec1 = 0.5M; decimal dec2 = 0.50M; Console.WriteLine(dec1); //Output: 0.5 Console.WriteLine(dec2); //Output: 0.50 Console.WriteLin...

Convert decimal to percent or shift decimal places. How

I have a that is generated from the diference of 2 numbers, but it return for exemple 0,07 for 7% and 0,5 for 50% i just want to fix to reach these goar, like 15,2% 13% and so on. How can I do that? do c# has something embeded on CLR to do that? ...

Why does isNaN(123.) return false?

Hi, Why does the Javascript function call isNaN(123.) return false? (notice the dot (.) after 123). 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?...

How was non-decimal money represented in software?

A lot of the answers to the questions about the accuracy of float and double recommend the use of decimal for monetary amounts. This works because today all currencies are decimal except MGA and MRO, and those have subunits of 1/5 so are still decimal-friendly. But what about the software used in U.S. stock markets when prices were in ...

.NET decimal.ToString(format) in Javascript

I have a string (€#,###.00) which works fine with aDecimal.ToString("€#,###.00") in .NET, i wonder if anyone knows how this could be achieved with javascript ...

Converting a decimal value to a 32bit floating-point hexadecimal

For a simple utility I'm working on, I need a script that converts a given decimal value to a 32bit floating-point hexadecimal value. For example, I know 1 is 3F800000 and 100 is 42C80000, however I don't know how to return these results with any number. If somebody knows a simple formula or even a complex way to go about doing this, ple...

Allowing decimal in numbers only field with JavaScript

Hi all, I have a function which I use to limit form inputs to numbers only, or number and decimals depending on the field. Allowing decimals and numbers is easy enough, but I am trying to take it a step further and allow only one decimal, while also making sure that decimal is not the first character in the field. I have successfully a...

Best way to display decimal without trailing zeros in c#

Is there a display formatter that will output decimals as these string representations in c# without doing any rounding? decimal -> string 20 -> 20 20.00 -> 20 20.5 -> 20.5 20.5000 -> 20.5 20.125 -> 20.125 20.12500 -> 20.125 0.000 -> 0 {0.#} will round, and using some Trim type function will not work with a bound numeric column ...

How to get max digits for the decimal part that non-integer numeric data types can support?

An user must enter a number into a mask-edit control. But that number is, depending on the underlying property, one of any .NET numeric type. For instance. If the property is sbyte, the maximum number the user can enter (with any digit, from 0 to 9) is 99 and the minimum is -99 (because sbyte ranges from -128 to 127). That is something ...

How do I convert a decimal integer into a single hexadecimal character? (C)

Hi, I am trying to convert a decimal integer into hexadecimal. I've done a lot of searching online, and have found many ways to do this. However, every way I found converts to a string; for example, I can convert 100 into "64". That isn't what I need to do. I want to be able to convert 100 into '0x64', which is an entirely different mat...

What is a good mapping of .NET decimal to SQL Server decimal?

I am having to interface some C# code with SQL Server and I want to have exactly as much precision when storing a value in the database as I do with my C# code. I use one of .NET's decimal type for a value. What datatype/precision would I use for this value in SQL Server? I am aware that the SQL Server decimal type is the type that mo...

Is it possible to store System.Decimal.MinValue and System.Decimal.MinValue in SQLite?

Considering that the maximum size of a data type supported by SQLite is 8 bytes, can I store a Decimal.MinValue, Decimal.MaxValue in a NUMERIC column. I am using the ADO.NET provider for SQLite by phxsoftware. Does the driver internally store the value as a string and do the conversion both ways? I do get a System.OverflowException whi...

How to literally define an array of decimals without multiple casting?

How can I define an array of decimals without explicitly casting each one? //decimal[] prices = { 39.99, 29.99, 29.99, 19.99, 49.99 }; //can't convert double to decimal //var prices = { 39.99, 29.99, 29.99, 19.99, 49.99 }; //can't initialize... decimal[] prices = { (decimal)39.99, (decimal)29.99, (decimal)29.99, (decimal)19.99, (decima...

MySQL Decimal Clarification

When using decimal in MySQL, does a value of (5,3) make it so the max number is 99.999? if not how do I specify that? My number is for currency so I need to use decimal, but it should not go over 99 and it must have 3 decimal places. ...

Overflow Exception when dividing two decimals in .NET

I'm having an issue trying to divide two decimals and then display the result. Annoyingly this is only happening on our server, and it appears to work perfectly fine if I run the code locally. This is the code that I am trying to run decimal dOne = -966.96M; decimal dTwo = 2300M; decimal dResult = Decimal.Round((dOne / dTwo), 28, ...

(La)TeX Base 10 fixed point arithmetic

I'm trying to implement decimal arithmetic in (La)TeX. I'm trying to use dimens to store the values. I want the arithmetic to be exact to some (fixed) number of decimal places. If I use 1pt as my base unit, then this fails, because \divide rounds down, so 1pt / 10 gives 0.09999pt. If I use something like 1000sp as my base unit, then ...

Django DecimalField lookups with MySQL not working

I'm migrating data from a legacy database that has many tables with primary keys defined like: `id` decimal(26,0) The id column will contain values that look like: 20080313154354198004 20081217165552136057 2008080416222952067 20060510151423191000 20060510151423191000 20070710143455874025 200806239353171091 Doing queries like: Rel...