decimal

Unable to restrict number of decimal digits when parsing a string to decimal in C#

霸气de小男生 提交于 2020-01-03 17:17:47
问题 I'm trying to parse a string to a decimal and the parsing should failed if there are more than 2 digits after the decimal point in the string. e.g: 1.25 is valid but 1.256 is invalid. I tried to use the decimal.TryParse method in C# to solve in the following manner but this does not help... NumberFormatInfo nfi = new NumberFormatInfo(); nfi.NumberDecimalDigits = 2; if (!decimal.TryParse(test, NumberStyles.AllowDecimalPoint, nfi, out s)) { Console.WriteLine("Failed!"); return; } Console

.NET: Convert datetime to decimal

僤鯓⒐⒋嵵緔 提交于 2020-01-03 17:17:16
问题 In SQL Server(T-SQL) you can convert a DateTime variable to a a decimal values like this: CONVERT(DECIMAL(20,10),@mytime) Sample Input: 2012-07-27 08:29:20.000 Sample Output: 41115.3537037037 Is there any equivalent method of converting a DateTime in .NET(C# or VB) to the same type of decimal? I am looking to compare times on different days. Calculating 41115.3537037037 % 1 = .3537037037 This would allow me to easily compare times on different dates. 回答1: It looks like this is "number of days

How to Parse a String with Multiple Decimal Points

心已入冬 提交于 2020-01-03 17:14:28
问题 I was wanting to parse a string such as "10.0.20" into a number in order to compare another string with the same format in C#.net For example I would be comparing these two numbers to see which is lesser than the other: if (10.0.30 < 10.0.30) .... I am not sure which parsing method I should use for this, as decimal.Parse(string) didn't work in this case. Thanks for your time. Edit: @Romoku answered my question I never knew there was a Version class, it's exactly what I needed. Well TIL.

How to Parse a String with Multiple Decimal Points

时光总嘲笑我的痴心妄想 提交于 2020-01-03 17:13:52
问题 I was wanting to parse a string such as "10.0.20" into a number in order to compare another string with the same format in C#.net For example I would be comparing these two numbers to see which is lesser than the other: if (10.0.30 < 10.0.30) .... I am not sure which parsing method I should use for this, as decimal.Parse(string) didn't work in this case. Thanks for your time. Edit: @Romoku answered my question I never knew there was a Version class, it's exactly what I needed. Well TIL.

Best Practice for financial calculations using JSTL/Tomcat [closed]

元气小坏坏 提交于 2020-01-03 16:37:14
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 7 months ago . I am building a new ecommerce platform using Tomcat/JSTL/MySQL/etc. I am aware of the various issues related to using floating point calculations - e.g. 12.3456000000000789... I know rounding vs truncation can also be an issue. Without moving all of the business logic into

How to create a number field that accepts numbers with comma or period in symfony 2

和自甴很熟 提交于 2020-01-03 13:07:33
问题 I have an application with a decimal field like: /** * @var decimal $amount * * @ORM\Column(name="amount", type="decimal", scale="2") */ private $amount; I want that the form to accept numbers with a format like "3,4" or "3.4". If I enter "3.4" the application save in the database "3.4", if I enter "3,4" the application saves in the database "34" (yes, without comma and without showing validation error!). (This is a known symfony bug: https://github.com/symfony/symfony/issues/2059 ) So, how

java (beginner) converting scientific notation to decimal

痴心易碎 提交于 2020-01-03 07:40:12
问题 if double d = 1.999e-4 I want my output to be 0.0001999. How can I do it? 回答1: NumberFormat formatter = new DecimalFormat("###.#####"); String f = formatter.format(d); You can explore the sub classes of NumberFormat class to know more details. 回答2: You can do it like this: double d = 1.999e-4; NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumFractionDigits(7); System.out.println(nf.format(d)); Check out the documentation of NumberFormat 's methods to format your double as you see

Rounding up float point numbers bash

房东的猫 提交于 2020-01-03 06:48:11
问题 Ok, so I'm trying to round up an input of 17.92857 , so that it gets an input of 17.929 in bash. My code so far is: read input echo "scale = 3; $input" | bc -l However, when I use this, it doesn't round up, it returns 17.928 . Does anyone know any solutions to this? 回答1: In case input contains a number, there is no need for an external command like bc . You can just use printf : printf "%.3f\n" "$input" Edit: In case the input is a formula, you should however use bc as in one of the following

How to write after decimal zero in ggplot (geom_text)

独自空忆成欢 提交于 2020-01-03 05:21:10
问题 I am wondering how i can put after decimal zero in the faceted ggplot plot. Following picture make it more clear. I would like to write r-squared =0.61 and 0.30 in two facets of ggplot using geom_text . It writes 0.61 properly but writes only 0.3 and not 0.30 in second plot. see the figure. My working data and codes are below. dput(ssdata) structure(list(Value = c(0.0776799352545487, 0.0249900650410425, 0.0530261633888124, 0.0567436050950435, 0.0120449632406235, 0.0148445528174501, 0

How scale is defined when decimal and bigint are divided?

馋奶兔 提交于 2020-01-02 12:49:32
问题 I have value A of type DECIMAL(19,8) - the scale is 8 , so the number of decimal digits that will be stored to the right of the decimal point is 8 . Now, I am dividing A on B , where B is BIGINT . For, example: SELECT CAST(3 AS DECIMAL(19, 8)) / CAST(27 AS BIGINT) -- 0.111111111111111111111111111 ,CAST(300 AS DECIMAL(19, 8)) / CAST(27 AS BIGINT) -- 11.111111111111111111111111111 ,CAST(75003 AS DECIMAL(19, 8)) / CAST(13664400 AS BIGINT) -- 0.005488934750153684025643277 the output values are