decimal

C# RegEx for decimal number

蹲街弑〆低调 提交于 2019-12-25 01:16:31
问题 I'm trying to make a Regular expression for a textbox which should only allow either only digits or decimals. For example, I should be able to enter both 10 and 10,350. The decimal seperator I'll use is "," and the decimal length don't need a limit. Anyone knows how I can make such a RegEx? 回答1: I'd go for decimal.TryParse() too, but if you really need a RegEx then something like this should work: (\d+(,\d*)?) 回答2: Just use decimal.TryParse or double.TryParse . 回答3: if you will use it in many

SQL Server 2005 varchar loses decimal places converting to a decimal

你。 提交于 2019-12-24 21:39:42
问题 Declare @BadDecimal varchar(5) Set @BadDecimal = '4.5' Declare @GoodDecimal Decimal Set @GoodDecimal = @BadDecimal Select @GoodDecimal --Outputs 5 Why? 回答1: Try Declare @GoodDecimal Decimal(2,1) edit: changed to (2,1) after request. 回答2: Coentjie beat me to it arrggg... You need to declare your decimals using this format Decimal(p,s) p = The maximum total number of decimal digits that can be stored, both to the left and to the right of the decimal point. The precision must be a value from 1

Changing a decimal format within the entire code using an option created in a switch menu

我的梦境 提交于 2019-12-24 21:26:26
问题 When writing the code, one of the tasks was to allow the user to change the decimal format within the entire program. The program consists of multiple calculators, all of them should be able to give decimal results. The user has then a choice of how many decimal places they would like to see. I know this can be done with format options just not sure how. /Answer given already 回答1: Create a variable containing a DecimalFormat DecimalFormat df = new DecimalFormat(); In menu option 4 where

Python: Decimal into time format

强颜欢笑 提交于 2019-12-24 18:22:16
问题 I'd like to convert a list of decimal time (HH,HHH) in time format HH:MM:SS 16. , 16.00000381, 16.00000572, 16.00000954, 16.00001144, 16.00001335, 16.00001717, 16.00001907, 16.00002098, 16.0000248 , 16.00002861, 16.00003052, 16.00003433, 16.00003624, 16.00003815, 16.00004196, 16.00004387, 16.00004768, 16.00004959, 16.00005341 Are there a way to do this in python? Thanks 回答1: Assuming the values represent hours: In [86]: import datetime as DT In [87]: data = [16. , 16.00000381, 16.00000572, 16

Converting a string to a mySql DECIMAL type

[亡魂溺海] 提交于 2019-12-24 17:26:00
问题 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 field, which has type DECIMAL(4,2). I heard that this was stored as a string but the database throws an error whenever I try and do this. Is there a PHP

SQL is rounding my decimal on cast

南笙酒味 提交于 2019-12-24 16:56:06
问题 I'm using SQL Server 2005. The datatype is varchar . I'm trying to convert numbers like 1250000 to 1.25 within the SQL query and drop the trailing zeroes. I have tried a number of things with no success - have run into 'trim is not a function', etc. Here's what I currently have, in each iteration that I have attempted. select top 30 var1, var2, var3, var4, CONVERT(DECIMAL(6,2), (var5 / 1000000)) as 'Number' from databasetable where var1 = x select top 30 var1, var2, var3, var4, cast((var5 /

SQL is rounding my decimal on cast

自古美人都是妖i 提交于 2019-12-24 16:55:10
问题 I'm using SQL Server 2005. The datatype is varchar . I'm trying to convert numbers like 1250000 to 1.25 within the SQL query and drop the trailing zeroes. I have tried a number of things with no success - have run into 'trim is not a function', etc. Here's what I currently have, in each iteration that I have attempted. select top 30 var1, var2, var3, var4, CONVERT(DECIMAL(6,2), (var5 / 1000000)) as 'Number' from databasetable where var1 = x select top 30 var1, var2, var3, var4, cast((var5 /

Convert hex character to decimal equivalent in MIPS

梦想的初衷 提交于 2019-12-24 16:06:48
问题 How do I take a single ASCII character and convert it to its decimal equivelant in MIPs? Do I simply have to have some conditions to subtract a certain amount from the ascii code to make it its decimal representation? 回答1: Here's a simplistic implementation of what Pax wrote (it assumes that hexadecimal digits - A to F are always upper case) File hextodec.c #include <stdio.h> /* *Converts an ASCII char to its decimal equivalent. *Returns -1 on error. * */ extern int hextodec(char* c); int

Decimal class rounding in Pandas

允我心安 提交于 2019-12-24 15:33:28
问题 i have problems rounding Decimals() inside a Pandas Dataframe. The round() method does not work and using quantize() neither. I've searched for a solution with no luck so far. round() does nothing, i asume it is meant for float numbers quantize() won't work because it is not a DataFrame function Any thoughts? 回答1: Since pandas has no quantize method i used the following to solve the problem: out.applymap(lambda x: x.quantize(dc.Decimal('1.00'))) 回答2: To round your decimal to 2 significant

This program doesn't work properly for decimals more than 10 digits?

折月煮酒 提交于 2019-12-24 12:34:24
问题 The below code is used to count number of digit in a given decimal. The problem is that it doesn't count digits more than 10. int NumDigits(int n) { int digits = 0; if (n <= 0) { n = -n; ++digits; } while (n) { n /= 10; ++digits; } return digits; } 回答1: It seems like your toolchain has a 32-bit int type. The maximum value representable in such a type is 2 31 -1 , or 2,147,483,647. As you can see, that's a 10-digit number. You'll need to use a different type that supports larger numbers if you