decimal

Why is Binary represented as a String?

帅比萌擦擦* 提交于 2021-02-05 07:11:25
问题 So I am quite new to Java and motivated to learn. This question might seem simple but I genuinely don't understand and have searched Google for answers (no luck). I am converting a decimal into Binary in Java. However, I thought representations of numbers are supposed to be given in data types int , double , and etc. The code is as follows : int decimal = 99; String binary = Integer.toBinaryString(decimal); System.out.println(binary); Why is it String binary , should it not be any of the

R cannot use hist() because “content not numeric” due to negative decimal numbers?

不羁的心 提交于 2021-02-04 19:49:26
问题 I am new to R and I am trying to draw a histogram using hist() of a list of 100,000 numbers like this -0.764 -0.662 -0.764 -0.019 0.464 0.668 0.464 but I cannot do it because R complains that the content is not numeric. This is what I've tried: I read the file using t <- read.table(file= "file.txt", sep = "\n", dec = ".", header = TRUE) , the data loads and looks well (I get the same values) I tried to make it numeric using as.numeric(c(t[,1])), sapply(t, as.numeric) , but I get completely

c++ cout << don't print '0' before decimal point

笑着哭i 提交于 2021-02-04 17:57:26
问题 I didn't find the solution to write decimal number inferior to 1 without the '0' before the decimal point. I want to display numbers at this format : ".1", ".2", etc... using : std::cout << std::setw(2) << std::setprecision(1) << std::fixed << number; always give me formats like "0.1", "0.2", etc... What do I wrong ? Thanks for your help 回答1: You need to convert it to a string and use it for printing. There is no way for a stream to print a floatingpoint without a leading zero, if there is

Convert a string to decimal in VB.NET

好久不见. 提交于 2021-02-04 17:16:40
问题 What will be the easiest way to convert a string to decimal? Input: a = 40000.00- Output will be 40,000.00- I tried to use this code: Dim a as string a = "4000.00-" a = Format$(a, "#,###.##") console.writeline (a) 回答1: Use Decimal.Parse to convert to decimal number, and then use .ToString("format here") to convert back to a string. Dim aAsDecimal as Decimal = Decimal.Parse(a).ToString("format here") Last resort approach (not recommended): string s = (aAsDecimal <0) ? Math.Abs(aAsDecimal)

Convert a string to decimal in VB.NET

被刻印的时光 ゝ 提交于 2021-02-04 17:16:27
问题 What will be the easiest way to convert a string to decimal? Input: a = 40000.00- Output will be 40,000.00- I tried to use this code: Dim a as string a = "4000.00-" a = Format$(a, "#,###.##") console.writeline (a) 回答1: Use Decimal.Parse to convert to decimal number, and then use .ToString("format here") to convert back to a string. Dim aAsDecimal as Decimal = Decimal.Parse(a).ToString("format here") Last resort approach (not recommended): string s = (aAsDecimal <0) ? Math.Abs(aAsDecimal)

Decimal to vulgar fraction conversion method- need help converting from Swift to Kotlin

跟風遠走 提交于 2021-01-29 11:06:23
问题 I found this beautiful decimal to fraction function: https://gist.github.com/natecook1000/9ecc976aaac9a035bddf I have manipulated the above for my apps necessity and would like help in making a Kotlin version. I have indeed tried making the conversion myself but I am a newbie coder period and have only been at Kotlin 3 weeks now. I don't have enough experience matching syntax and semantics between languages to do it all myself. Help appreciated :) I changed the above to output custom Unicode

How to represent a 5 digit decimal value as a 24 bit value?

走远了吗. 提交于 2021-01-29 09:20:26
问题 I'm trying to convert a 5 digit decimal value (ranging from 00001 to 99999) and somehow represent it as a 24-bit value split into 3 bytes but have tried every conversion and bitshift tactic I know, but keep getting stuck :/ Example: decimal value is 12345, and I need to send 3 hex values [aa][bb][cc], which would consist of: [aa] - least significant | [bb] - middle | [cc] - most significant I'm hoping I'm not in over my head and that there is a simple answer, thanks in advance! 回答1: Try

Why does converting between decimal and hex throw a formatexception?

时间秒杀一切 提交于 2021-01-29 07:46:26
问题 When I compile and run the below code, it throws the following exception: Unhandled Exception: System.FormatException: The specified format 'X' is invalid at System.NumberFormatter.NumberToString (System.String format, System.Globalization.NumberFormatInfo nfi) [0x00000] in :0 at System.NumberFormatter.NumberToString (System.String format, Decimal value, IFormatProvider fp) [0x00000] in :0 at System.Decimal.ToString (System.String format, IFormatProvider provider) [0x00000] in :0 at System

Method to parse decimals with various decimal/radix separators

醉酒当歌 提交于 2021-01-29 06:52:37
问题 I do a lot of file parsing, which involves parsing data types like decimal. To help make the code more readable, I've been using the following method: public static decimal? ToDecimal(this string data) { decimal result; if (decimal.TryParse(data, NumberStyles.Integer | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out result)) return result; return null; } This works fine for decimals which are represented with a full-stop/period as the decimal separator. However, I'd like

How to get WooCommerce variation prices to have two decimals (trailing zero)?

风流意气都作罢 提交于 2021-01-29 06:23:19
问题 I have a product with variations, that is being displayed by the templates/single-product/add-to-cart/variation.php template, which uses JavaScript-based templates {{{ data.variation.display_price }}} . When I have price that end with a zero, for example, € 12.50, the price on the front-end will be displayed as € 12.5 (without the zero). I want to have the price include the trailing zero. I've tried the following filter, but it does not work. add_filter( 'woocommerce_price_trim_zeros', 'wc