numbers

Common strategies to deal with rounding errors in currency-intensive soft?

喜夏-厌秋 提交于 2019-11-30 12:46:25
What is your advice on: compensation of accumulated error in bulk math operations on collections of Money objects. How is this implemented in your production code for your locale? theory behind rounding in accountancy. any literature on topic. I currently read Fowler . He mentions Money type, it's typcal structure (int, long, BigDecimal), but says nothing on strategies. Older posts on money-rounding ( here , and here ) do not provide a details and formality I need. Thoughts I found in the inet relate to "Round half even" as the best way to balance error. Thanks for help. There are many

Decimal Pipe in Angular 2 - Commas Only, No Decimal Places

让人想犯罪 __ 提交于 2019-11-30 12:43:58
I currently use this pipe {{ product.productPrice | number:'.2-2' }} And result is 1,000,000.00 but I want to remove the .00 How do you do that? Use this : {{product.productPrice | number: '1.0-0'}} 1.0-0 means: at least one digit before decimal point, 0 digits after decimal point. https://angular.io/api/common/DecimalPipe 来源: https://stackoverflow.com/questions/45955101/decimal-pipe-in-angular-2-commas-only-no-decimal-places

Get number of digits before decimal point

有些话、适合烂在心里 提交于 2019-11-30 12:37:04
问题 I have a variable of decimal type and I want to check the number of digits before decimal point in it. What should I do? For example, 467.45 should return 3 . 回答1: Solution without converting to string (which can be dangerous in case of exotic cultures): static int GetNumberOfDigits(decimal d) { decimal abs = Math.Abs(d); return abs < 1 ? 0 : (int)(Math.Log10(decimal.ToDouble(abs)) + 1); } Note, that this solution is valid for all decimal values UPDATE In fact this solution does not work with

How to format numbers with 00 prefixes in php?

↘锁芯ラ 提交于 2019-11-30 11:18:27
问题 I'm trying to generate invoice numbers. They should always be 4 numbers long, with leading zeros, for example : 1 -> Invoice 0001 10 -> Invoice 0010 150 -> Invoice 0150 etc. 回答1: Use str_pad(). $invID = str_pad($invID, 4, '0', STR_PAD_LEFT); 回答2: Use sprintf : http://php.net/function.sprintf $number = 51; $number = sprintf('%04d',$number); print $number; // outputs 0051 $number = 8051; $number = sprintf('%04d',$number); print $number; // outputs 8051 回答3: Use (s)printf printf('%04d',$number);

PHP - Get length of digits in a number

有些话、适合烂在心里 提交于 2019-11-30 11:08:12
I would like to ask how I can get the length of digits in an Integer. For example: $num = 245354; $numlength = mb_strlen($num); $numlength should be 6 in this example. Somehow I can't manage it to work? Thanks EDIT: The example code above --^ and its respective method mb_strlen(); works just fine. Maybe: $num = 245354; $numlength = strlen((string)$num); Some math sometime helps. Everything you need is to invoke floor(log10($num) + 1) with check for 0. $num = 12357; echo $num !== 0 ? floor(log10($num) + 1) : 1; Basically it does the logarithm with base 10 then makes floor of it and adds 1. More

Algorithm in C - playing with numbers - number with 3 in units place

孤者浪人 提交于 2019-11-30 11:06:49
问题 I came across this question in an interview. Any number with 3 in its units position has at least one multiple containing all ones. For instance, a multiple of 3 is 111, a multiple of 13 is 111111. Given a number ending in 3, I was asked the best method to find its multiple containing all 1's. Now a straightforward approach is possible, where you do not consider space issues but as the number grows, and sometimes even if it doesn't, an int (or a long int at that!) in C cannot hold that

Numeric TextBox in C# - WPF [duplicate]

二次信任 提交于 2019-11-30 10:08:12
This question already has an answer here: How do I get a TextBox to only accept numeric input in WPF? 30 answers i want to create a textbox in WPF that only accept numbers... i've reaserched and people say to use keypress event or masked textbox, but they are in windows forms... Maciek For WPF: private void textBox1_PreviewTextInput(object sender, TextCompositionEventArgs e) { if (!char.IsDigit(e.Text, e.Text.Length - 1)) e.Handled = true; } For Windows Forms: private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if (!char.IsDigit(e.KeyChar) ) e.Handled = true; } 来源: https:/

Most elegant way to detect if a String is a number?

自古美人都是妖i 提交于 2019-11-30 09:32:05
Is there a better, more elegant (and/or possibly faster) way than boolean isNumber = false; try{ Double.valueOf(myNumber); isNumber = true; } catch (NumberFormatException e) { } ...? Edit : Since I can't pick two answers I'm going with the regex one because a) it's elegant and b) saying "Jon Skeet solved the problem" is a tautology because Jon Skeet himself is the solution to all problems. I don't believe there's anything built into Java to do it faster and still reliably, assuming that later on you'll want to actually parse it with Double.valueOf (or similar). I'd use Double.parseDouble

how to generate integer random number in fortran 90 in the range [0,5]?

感情迁移 提交于 2019-11-30 09:18:29
I am kind of new in the fortran proramming. Can anyone please help me out with the solution. i am having a problem of generating integer random number in the range [0,5] in fortran random number using random_seed and rand What about: program rand_test use,intrinsic :: ISO_Fortran_env real(REAL32) :: r(5) integer :: i(5) ! call init_random_seed() would go here call random_number(r) ! Uniform distribution requires floor: Thanks to @francescalus i = floor( r*6._REAL32 ) print *, i end program francescalus To support the answer by Alexander Vogt, I'll generalize. The intrinsic random_number(u)

prolog convert numbers into roman numerals

限于喜欢 提交于 2019-11-30 09:13:41
问题 i have this code that converts integers into roman numerals i need to add a function that compares an integer with a roman numeral input and show if it's try or false, for example: roman(v,5). true toroman(0). toroman(N) :- N < 4, put("I"), M is N - 1, toroman(M). toroman(N) :- N = 4, put("I"), put("V"). toroman(N) :- N = 5, put("V"). toroman(N) :- N < 9, put("V"), M is N - 5, toroman(M). toroman(N) :- N = 9, put("I"), put("X"). toroman(N) :- N < 40, put("X"), M is N - 10, toroman(M). toroman