decimal

Convert decimal feet to feet and inches?

☆樱花仙子☆ 提交于 2020-01-15 11:34:30
问题 How would I go about converting a measurement from, for example, 12.5 feet to 12ft 6in? How would I created that second number which reads only the decimal place when multiplying by 12? right now I have double Measurement01 using other variables and some math to get me the feet in decimals. I send that to a textview with farf.setText(Measurement01 + " " + "ft"); Any help would be appreciated! 回答1: Substract the integer portion: float measurement = 12.5; int feet = (int)measurement; float

strange behavior when fixing integer lengths in bash

旧街凉风 提交于 2020-01-15 10:13:25
问题 In my bash script, I set-up the following operations year=0050 echo $(printf %04d $year) >0040 I do not understand why 0040 is returned instead of 0050. I eventually found that to get the system to print 0050 correctly, I will have to do this instead. year=50 echo $(printf %04d $year) >0050 Are there any insights as to why the first case happens? 回答1: It's because numbers with a leading zero are interpreted as octal by Bash, and octal 50 is decimal 40. To fix it, you can either strip the

How to preserve leading zeros when converting to a decimal in oracle

寵の児 提交于 2020-01-15 09:22:47
问题 I am running the below query in oracle. WITH ta AS ( SELECT account_coid ,txn_id ,cbdev.cbzdt(effective_date) AS effective_date ,cbdev.cbchr(utl_raw.substr(txn_data, 113, 20)) AS CESG_amt FROM bs_transaction WHERE sub_type = 127469880) SELECT cast(ta.CESG_amt as DECIMAL (20,2)) AS cesg_amt from ta inner join .... Here, i m getting the result ( cesg_amt ) as -156.57 . But i need the result as -0000000000156.57 . I need the leading zeros with - retained (leading 0's and also the two digits

What Are the Maximum Number of Base-10 Digits in the Integral Part of a Floating Point Number

大城市里の小女人 提交于 2020-01-15 03:07:14
问题 I want to know if there is something in the standard, like a #define or something in numeric_limits which would tell me the maximum number of base-10 digits in the integral part of a floating point type. For example, if I have some floating point type the largest value of which is: 1234.567. I'd like something defined in the standard that would tell me 4 for that type. Is there an option to me doing this? template <typename T> constexpr auto integral_digits10 = static_cast<int>(log10(numeric

What Are the Maximum Number of Base-10 Digits in the Integral Part of a Floating Point Number

末鹿安然 提交于 2020-01-15 03:03:11
问题 I want to know if there is something in the standard, like a #define or something in numeric_limits which would tell me the maximum number of base-10 digits in the integral part of a floating point type. For example, if I have some floating point type the largest value of which is: 1234.567. I'd like something defined in the standard that would tell me 4 for that type. Is there an option to me doing this? template <typename T> constexpr auto integral_digits10 = static_cast<int>(log10(numeric

Doing a Math.Round(x,2) on a decimal value, but need to ensure 2 numbers after decimal as its money

坚强是说给别人听的谎言 提交于 2020-01-14 14:52:13
问题 Some values are returning 2.0 but I need it to be 2.00 as this is a money value that is displayed to the web page. I am doing: Math.Round(value, 2); Is there a way to force it to 2 numbers after the decimal? 回答1: You should be using a decimal to store monetary values. But regardless of whether you are using a decimal or floating point type, your question asks how the number can be displayed with two decimal places. Use money.ToString("0.00") to display two decimal places. 回答2: If your using

Comparing two decimals

自作多情 提交于 2020-01-14 13:14:37
问题 I want to compare two decimals in c# with some margin of error. Can anyone point out problem with the following code. Note that I am interested in 6 decimal places after that I could ignore the values. var valOne = decimal.Round(valueOne, 6); var valTwo = decimal.Round(valueTwo, 6); var difference = Math.Abs(valOne - valTwo); if (difference > 0.0000001m) { Console.WriteLine("Values are different"); } else { Console.WriteLine("Values are equal"); } or is there a better way. 回答1: If you are

Comparing two decimals

[亡魂溺海] 提交于 2020-01-14 13:10:12
问题 I want to compare two decimals in c# with some margin of error. Can anyone point out problem with the following code. Note that I am interested in 6 decimal places after that I could ignore the values. var valOne = decimal.Round(valueOne, 6); var valTwo = decimal.Round(valueTwo, 6); var difference = Math.Abs(valOne - valTwo); if (difference > 0.0000001m) { Console.WriteLine("Values are different"); } else { Console.WriteLine("Values are equal"); } or is there a better way. 回答1: If you are

DisplayFormat not getting applied on decimal value

半世苍凉 提交于 2020-01-14 07:35:09
问题 I have a model property I'm trying to render using an EditorFor template, and I'm trying to apply formatting using the DisplayFormat attribute. However, it's not working at all -- it's totally being ignored. Here is my template: @model System.Decimal? @Html.TextBoxFor(m => m) Here is my model: [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:0.00}")] public decimal? Retail { get; set; } Here is my view: @Html.EditorFor(m => m.Retail) But it's rendering a textbox with the

Is there a better way to convert a Double to it's exact decimal String?

£可爱£侵袭症+ 提交于 2020-01-13 19:17:07
问题 I tried many ways to convert a Double to it's exact decimal String with String.format() and DecimalFormater and I found this so far : String s = "-.0000000000000017763568394002505"; Double d = Double.parseDouble(s) * 100; System.out.println((new java.text.DecimalFormat("###########################.################################################################################")).format(d)); (https://ideone.com/WG6zeC) I'm not really a fan of my solution because it's ugly to me to make a huge