decimal

Convert decimal to percent or shift decimal places. How

那年仲夏 提交于 2019-12-05 01:53:36
I have a that is generated from the diference of 2 numbers, but it return for exemple 0,07 for 7% and 0,5 for 50% i just want to fix to reach these goar, like 15,2% 13% and so on. How can I do that? do c# has something embeded on CLR to do that? You can use the Percentage Custom Numeric Format String . This will do it without you having to multiply yourself. For example, you can do: double value = 0.152; string result = value.ToString("#0.##%"); If your locale is set to European (my guess based off the format you wrote), you'll get a string with the value of "15,2%". You can also just use the

Efficiently convert byte array to Decimal

牧云@^-^@ 提交于 2019-12-05 01:39:26
问题 If I have a byte array and want to convert a contiguous 16 byte block of that array, containing .net's representation of a Decimal , into a proper Decimal struct, what is the most efficient way to do it? Here's the code that showed up in my profiler as the biggest CPU consumer in a case that I'm optimizing. public static decimal ByteArrayToDecimal(byte[] src, int offset) { using (MemoryStream stream = new MemoryStream(src)) { stream.Position = offset; using (BinaryReader reader = new

Android - Limit only one decimal point enter into a EditText

自作多情 提交于 2019-12-05 01:34:13
问题 I need help to only allow one decimal point to be entered into a EditText view. An example: I don't want 123.45.2 or 123..452 to be allowed. Once one decimal point is entered, no more are allowed. 回答1: Play around with this however you like it. myEditText.setKeyListener(DigitsKeyListener.getInstance(true,true)); Returns a DigitsKeyListener that accepts the digits 0 through 9, plus the minus sign (only at the beginning) and/or decimal point (only one per field) if specified. 回答2: You can set

Formatting a double in JSF

会有一股神秘感。 提交于 2019-12-05 01:16:34
I have a problem similar to the one found here : JSF selectItem label formatting . What I want to do is to accept a double as a value for my and display it with two decimals. Can this be done in an easy way? I've tried using but that seems to be applied on the value from the inputText that is sent to the server and not on the initial value in the input field. My code so far: <h:inputText id="december" value="#{budgetMB.december}" onchange="setDirty()" styleClass="StandardBlack"> <f:convertNumber maxFractionDigits="2" groupingUsed="false" /> </h:inputText> EDIT: The above code actually works. I

Rounding to the nearest hundredth of a decimal in JavaScript

泄露秘密 提交于 2019-12-05 01:11:22
I'm doing simple math in JavaScript using variables to represent the numbers. Here is an example of my code: var ones = 0; var fives = 0; function results (){ _fives = (fives * 5); var res = (_fives + ones); document.innerHTML = res; } This isn't the full code but basically I'm having the user enter the amount of bills and coins from 1 cent coins up to $100 bills. The code multiplies the amount of bills to the amount the bill is worth. This is no problem works just fine... For some reason on some of my results it shows a decimal like 1.899999999997 not sure how this is happening. Is there a

C# Casting to a decimal

旧巷老猫 提交于 2019-12-05 01:00:33
What, if any, is the difference between? decimal d = (decimal) myDouble; decimal d = new decimal(myDouble); decimal d = Convert.ToDecimal(myDouble); There is no difference. If you look at the source: In Decimal: public static explicit operator decimal(double value) { return new decimal(value); } In Convert: public static decimal ToDecimal(float value) { return (decimal) value; } So in the end they all call new decimal(double) . They all achieve the same results. However, here's a more broken down explanation: Method 1 creates a new variable which explicitly casts myDouble to type decimal .

Mysql calculation issues: 1+1=1.999999999

僤鯓⒐⒋嵵緔 提交于 2019-12-05 00:07:49
问题 The problem is this, when I add two or more doubles from a table to a view, instead of giving me the right results, it adds a about ten or so more digits. For example 0.5+1.5=1.99999999998 or 5.5+8.5=14.0000000001. Any ideas? (I know this is sort of n00b question and I remember having to deal with stuff like that in the exams at 9th grade, but I just cannot remember how I did it back then :P) 回答1: http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_format You can format

Django object filter - price behaving strangely, eg 170 treated as 17 etc

北战南征 提交于 2019-12-04 21:23:24
I have a simple object filter that uses price__lt and price__gt . This works on a property on my product model called price, which is a CharField [string] (decimal saw the same errors, and caused trouble with aggregation so reverted to string). It seems that when passing in these values to the filter, they are treated in a strange way, eg 10 is treated as 100. for example: /products/price/10-200/ returns products priced 100-200. the filters are being passed in as filterargs: FILTER ARGS: {'price__lt': '200', 'price__gt': '10'} . This also breaks in the sense that price/0-170 will NOT return

How can I change DecimalFormat behavior based on input length?

喜欢而已 提交于 2019-12-04 20:31:42
问题 I am using the following DecimalFormat pattern: // Use ThreadLocal to ensure thread safety. private static final ThreadLocal <NumberFormat> numberFormat = new ThreadLocal <NumberFormat>() { @Override protected NumberFormat initialValue() { return new DecimalFormat("#,##0.00"); } }; This performs the following conversions: 1 -> 1.00 1.1 -> 1.10 1.12 -> 1.12 I now have an additional requirement. 1.123 -> 1.123 1.1234 -> 1.123 That means that when there are fewer than two decimal places, I will

Common lisp integer to hex conversion

╄→гoц情女王★ 提交于 2019-12-04 20:31:15
问题 Is there a similar function to (parse-integer "ff" :radix 16) that will take me back the other way? If I have the int 255 how do I convert it to the string ff? 回答1: (write-to-string 255 :base 16) 回答2: You can also use format with the ~X radix designator: CL-USER> (format t "~X" 255) FF NIL To get the leading 0x and a minimum width of, say, four padded with zeros, use CL-USER> (format t "0x~4,'0X" 255) 0x00FF NIL To force the digits from 10 to 15 to be lowercase, use the case conversion