Questions tagged [decimal]

Decimal is the name for our common base-ten numeral system. It may also refer to non-integer values expressed with a decimal point.

Decimal is the base-10 positional numeral system. It is the ordinary numeral system we use; it can be used to represent both integers and (using a decimal point) non-integer values.

Related tags

7532 questions
3
votes
5 answers

Format a double to two digits after the comma without rounding up or down

I have been searching forever and I simply cannot find the answer, none of them will work properly. I want to turn a double like 0.33333333333 into 0,33 or 0.6666666666 into 0,66 Number like 0.9999999999 should become 1 though. I tried various…
FrozenHaxor
  • 59
  • 1
  • 2
  • 8
3
votes
3 answers

PHP decimal position of math result

If variable A = 0.07 when echoed and variable B = 2100.00 when echoed if we: $c = $a * $b; when the end result is a whole # ( i.e. $c = 147) is there any way to force the result to keep 2 decimal places and hold the trailing zero's so that ( $c =…
DMSJax
  • 1,709
  • 4
  • 22
  • 35
3
votes
2 answers

set double format with 2 decimal places

I have a short equation: double compute,computed2; compute=getminutes/60; where getminutes is int and I want to set the equivalent of compute with 2 decimal places. 0.00 how can I format the equivalent with 2 decimal places? Example: compute=45/60…
Maguzu
  • 433
  • 3
  • 7
  • 14
3
votes
1 answer

mvc4 - db.SaveChanges() - decimal value out of range

I'm building an MVC4 application that requires me to generate a 21 digit key when 'creating' a new record. Here is my context where i'm defining the db columns: public class cust { public int ID { get; set; } public decimal…
Mike Wallace
  • 543
  • 4
  • 15
3
votes
4 answers

How to see if a number ends in .0

I am trying to run a test if the number ends in .0 I am running a program with numbers orders of magnitude apart so I can't estimate to a certain amount of digits. using % doesn't work either because then certain numbers are excluded. All the…
Felis Vulpes
  • 33
  • 2
  • 7
3
votes
5 answers

n bit 2s binary to decimal in C++

I am trying to convert a string of signed binary numbers to decimal value in C++ using stoi as shown below. stoi( binaryString, nullptr, 2 ); My inputs are binary string in 2s format and stoi will work fine as long as the number of digits is…
kona
  • 143
  • 1
  • 3
  • 8
3
votes
3 answers

Regex to match decimal value

I have the following regex to match decimals: @"[\d]{1,4}([.][\d]{1,2})?" but I am able to input multiple decimal dots. How can I prevent this? In general, I can have input strings like "2000" or "2000.22". I have tried to use decimal.TryParse but…
Igor S
  • 638
  • 7
  • 15
3
votes
1 answer

JSONObject removes decimal dot, if round number

Using a rest service, we are transfering values using JSON. At some point, we need to decide, wheter the incoming value was a long or a double. While Double d = 17.0; System.out.println("toString(): " + d.toString()); will result in toString():…
dognose
  • 20,360
  • 9
  • 61
  • 107
3
votes
2 answers

PHP calculating with decimals

I get some rewards from a XMl and want to calculate the sum. Why isn't the output for $M_commission 166.63? $i = 0; $commission_trans = 0; foreach($responseXml->lead as $lead) { if ($i == 0) { $last_trans = $lead->leadTime; } …
Scripter
  • 558
  • 2
  • 8
  • 20
3
votes
1 answer

MYSQL CAST AS DECIMAL for VARCHAR field

I have been given an e-commerce project to fix some errors on by my client. The earlier dumb developers had given the price field VARCHAR datatype instead of so very obvious INTEGER in the products table, and so the next set of developers in order…
coder101
  • 1,601
  • 2
  • 21
  • 41
3
votes
4 answers

how to solve attempted to divide by zero in c#?

I am getting this bug, I wrote code like this below code: decimal Amnt; decimal.TryParse(txtAmnt.Text, out Amnt); int tnure=1; int.TryParse(txtTnre.Text, out tnure); txtDdctAmnt.Text = (Amnt /tnure).ToString("0.00"); when in textbox value 0 I am…
user1899761
  • 39
  • 1
  • 1
  • 5
3
votes
2 answers

python 3 round function approximation

I am facing a problem with the round function of python. When I round with 2 digits by executing round(0.715,2) the answer is 0.71, similarly when I execute round(0.615,2) the result is 0.61. But when I execute round(0.515,2) it gives 0.52,…
3
votes
2 answers

Why does specifying a numeric value for a control's property in the designer result in new decimal(new int[] {... in the code?

In my C#.Net WinForm app in VS2005, I have a NumericUpDown control. In the designer, I set the Minimum property of the NumericUpDown to -65535. In the form's .designer.cs code, I expected to see this: this.myNumericUpDown.Minimum = -65535; but…
JeffH
  • 10,254
  • 2
  • 27
  • 48
3
votes
1 answer

How do I access rounding modes defined in IEEE 754 in python?

I have the need to compute exactly in single precision floating points in Python. The options I've tried are decimal.Decimal and numpy.float32. However Decimal is not based on IEEE 754, and float32 cannot allow the use of rounding modes. It is…
koo
  • 2,888
  • 1
  • 23
  • 29
3
votes
2 answers

how to get two variables to print with one in decimal form

I am very new. apologies in advance for my coding. I need to print a table that shows year and then a tab over, and then the value with a next line. The value has to be in decimal form. I have been reading and searching and mixing my code around. …
Lish
  • 231
  • 4
  • 6
  • 14