The main question: How many digits?
Let me explain. I have a number in binary system: 11000000 and in decimal is 192.
After converting to decimal, how many digits it will have (in dicimal)? In my example, it's 3 digits. But, it isn't a problem. I've searched over internet and found one algorithm for integral part and one for fractional...
Hi all,
I need to validate a textbox input and can only allow decimal inputs like:
X,XXX (only one digit before decimal sign and a precision of 3)
I'm using c#
Should it be something like ^[0-9]+(.[0-9]{1,2})?$
Thanks!!!
...
is it possible for a udf to return the same data type as one of its parameters?
i would like my udf to accept a decimal of any precision and scale
and return the same type.
...
I need help with displaying a decimal value on a Windows Form.
I have a class with a method to calculate an interest amount, listed below.
public virtual decimal CalculateInterest()
{
interest = (interestRate/100) * base.getBalance();
return interest;
}
In my main form, I am using this method when a button is clicked, listed ...
Hi,
I have a custom modal class which contains a decimal member and a view to accept entry for this class. Everything worked well till I added javascripts to format the number inside input control. The format code format the inputted number with thousand separator ',' when focus blur.
The problem is that the decimal value inside my mod...
A common international issue is the conversion of double values represented in strings.
These stuff is found in a lot of areas.
Starting with csv files which are either called
comma separated
or
character separated
because sometimes they are stored like
1.2,3.4
5.6,6.4
in English regions or
1,2;3,4
5,6;6,4
in for example Ger...
I'm trying to calculate the sum of an array of decimal values in PHP, but for some reason it keeps rounding to integers.
for example:
$oldArray = array(0.00,1000.11,988.92,978.22,964.01,953.07,948.82,917.26,902.56,913.21,904.08,898.86,892.79);
$myVar = 0.0;
for($k=1;$k<10;$k++)
{
$myVar += $oldArray[$k];
}
print_r($myVar);
$oldArray ...
I have a table with two decimal(18,0) fields.
I am inserting into this table, two decimal values. For example, 1.11
When I select from the table (with no casts), I get 1.
I'm losing all percision and I have no clue why.
insert into TEST values (153, 'test', 'test', 1, 1, 1.11, 1.11)
Select * from TEST and they are 1 and 1 instead of...
python decimal comparison
>>> from decimal import Decimal
>>> Decimal('1.0') > 2.0
True
I was expecting it to convert 2.0 correctly, but after reading thru PEP 327 I understand there were some reason for not implictly converting float to Decimal, but shouldn't in that case it should raise TypeError as it does in this case
>>> Decimal...
Hi all!
First of all sorry for my English, it's not my native language.
So, I am planning to make an application (PHP/MySQL) which deals a lot with money, and I am thinking about how to store and operate with the money, referring to PHP float data type and MySQL decimal.
I was thinking of two options. One of them is to operate and st...
Lets say that input from the user is a decimal number, ex. 5.2155 (having 4 decimal digits). It can be stored freely (int,double) etc.
Is there any clever (or very simple) way to find out how many decimals the number has? (kinda like the question how do you find that a number is even or odd by masking last bit).
...
I have an IDataRecord reader that I'm retrieving a decimal from as follows:
decimal d = (decimal)reader[0];
For some reason this throws an invalid cast exception saying that the "Specified cast is not valid."
When I do reader[0].GetType() it tells me that it is an Int32. As far as I know, this shouldn't be a problem....
I've tested ...
I have a string in the format: 'nn.nnnnn' in Python, and I'd like to convert it to an integer.
Direct conversion fails:
>>> s = '23.45678'
>>> i = int(s)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '23.45678'
I can convert it to a decimal by using:
>>> ...
One error I stumble upon every few month is this one:
double x = 19.08;
double y = 2.01;
double result = 21.09;
if (x + y == result)
{
MessageBox.Show("x equals y");
}
else
{
MessageBox.Show("that shouldn't happen!"); // <-- this code fires
...
I'm working with fractions using Python's decimal module and I'd like to get just the repeating part of a certain fraction. For example: if I had 1/3 I'd like to get 3, if I had 1/7 I'd like to get 142857. Is there any standard function to do this?
...
These lines in C#
decimal a = 2m;
decimal b = 2.0m;
decimal c = 2.00000000m;
decimal d = 2.000000000000000000000000000m;
Console.WriteLine(a);
Console.WriteLine(b);
Console.WriteLine(c);
Console.WriteLine(d);
Generates this output:
2
2.0
2.00000000
2.000000000000000000000000000
So I can see that creating a decimal variable from a ...
Yesterday I asked this general question about decimals and their internal precisions. Here is a specific question about the scenario I'm trying to address.
I have column in SqlServer that is typed - decimal(18,6).
When I fetch these values, the .net decimals that are created match the precision in the database. They look like this:
1...
Does anyone know of an elegant way to get the decimal part of a number only? In particular I am looking to get the exact number of places after the decimal point so that the number can be formatted appropriately. I was wondering if there is away to do this without any kind of string extraction using the culture specific decimal separator...
I need to do calculations (division or multiplication) with very large numbers. Currently I am using Double and getting the value round off problems. I can do the same calculations accurately on C# using Decimal type. I am looking for a method to do accurate calculations in VB6.0 and I couldn't find a Decimal type in VB6.0.
What is the...
I keep seeing people using doubles in C#. I know I read somewhere that doubles sometimes lose precision.
My question is when should a use a double and when should I use a decimal type?
Which type is suitable for money computations? (ie. greater than $100 million)
...