numbers

DecimalFormat - keep all decimal numbers

送分小仙女□ 提交于 2019-12-10 14:10:50
问题 I'm using DecimalFormat to format doubles into a String. This String is then integrated into my presentation layer. Problem : I want to keep ALL decimals. Example: "12345678.123456789" Question : What format should I use? Remark : I use a different Locale to support multiple layouts. Format: #.## -> This uses ALL numbers BEFORE the decimal, but ROUNDS the numbers AFTER the decimal. I could use #.######### for the big decimal, but what if the decimal is even longer? I found my small test

Split a number into a list of digits in Prolog

こ雲淡風輕ζ 提交于 2019-12-10 13:57:32
问题 I've been having trouble trying to split numbers into lists using Prolog, e.g. 123456 becomes [1,2,3,4,5,6] . Can you please help me work out how to do this? 回答1: the builtins available are ISO standard: ?- number_codes(123456,X),format('~s',[X]). 123456 X = [49, 50, 51, 52, 53, 54]. ?- number_chars(123456,X),format('~s',[X]). 123456 X = ['1', '2', '3', '4', '5', '6']. I also have some very old code I developed for my interpreter. := must be renamed is to run with standard Prologs. But then

Dividing prices by 3

拈花ヽ惹草 提交于 2019-12-10 13:32:12
问题 For accounting program I need to divide a price by 3 so it can be shared over 3 months For example 9€ 3€ first month 3€ second month 3€ third month Now this would be price/3 But what if the number is 10? 3,33€ first month 3,33€ second month 3,33€ last month 3,33€*3 =€9.99 One cent has gone missing. How can I make it so the ouput would become 3,33€ , 3,33€ , 3,34€? 回答1: As Bathsheba said, ask your users first. Here's a technique that I've used often in such scenarios. This method will ensure

Python format default rounding when formatting float number

核能气质少年 提交于 2019-12-10 13:21:48
问题 I'm trying to solve some floating-point problems in my code in Python 2.7.10. When testing I've encountered a strange behaviour with the format method: print "{}".format(0.3000000000004) # 13 decimals Prints: 0.3 But: print "{}".format(0.300000000004) # 12 decimals Prints: 0.300000000004 Since I'm not specifying the format, why does it round the first number? Is there a default number of allowed decimal places? 回答1: Since you do not specify a format, the default type coercion to string is

how to generate gaussian pseudo random numbers in c for a given mean and variance?

两盒软妹~` 提交于 2019-12-10 13:18:09
问题 I have a code here which generates random numbers having a mean 0f 1 and std deviation of 0.5. but how do i modify this code so that i can denerate gaussian random numbers of any given mean and variance? #include <stdlib.h> #include <math.h> #ifndef M_PI #define M_PI 3.14159265358979323846 #endif double drand() /* uniform distribution, (0..1] */ { return (rand()+1.0)/(RAND_MAX+1.0); } double random_normal() /* normal distribution, centered on 0, std dev 1 */ { return sqrt(-2*log(drand())) *

How to get rid of zeros in the section numbering in LATEX report document class?

六月ゝ 毕业季﹏ 提交于 2019-12-10 12:58:22
问题 So I'm writing a report using Latex and the document class I am using is report: \documentclass[a4paper]{report} But for some reason the section numbering is written so that it is preceded with "0.", for example it looks like: 0.1 Introduction 0.2 Theory 0.3 Experimental Method and so on. Can somebody help me get rid of those zeros so that it appears how it is supposed to be? Any help is very appreciated, thanks. 回答1: report assumes you'll be using \chapter s as your main sectional unit. As

how can i get the Unicode infinity symbol converted to String

送分小仙女□ 提交于 2019-12-10 12:58:06
问题 I want to use the infinity symbol (8 lying sideways) in java. furthermore i want to use it as a String component. i did not find a working charcode/ascii code for this (is there any?). i tried: String s=Character.toString(236); String s=Character.toString('236'); am i missing something? i got this now: System.out.println(Character.toString('\u221E')); but the output is ? i am using java 1.7 jdk and eclipse. why is the infinity sign not showing up? 回答1: You need the Unicode infinity sign, U

Custom radix columns (+special characters) [closed]

强颜欢笑 提交于 2019-12-10 12:37:45
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed last year . Currently I'm using this code to convert a number into an base36 -string: let number = 300293338 let base36 = String(number, radix: 36); print(base36) // 4ysbtm But I'm wondering how it's possible to generate my own alphabet with a kind of a Base10 to AnyBase conversion using Swift.

Haskell numbers and type system?

情到浓时终转凉″ 提交于 2019-12-10 12:32:50
问题 I have this piece of Javascript code: N1 = Math.floor(275 * month / 9) N2 = Math.floor((month + 9) / 12) N3 = (1 + Math.floor((year - 4 * Math.floor(year / 4) + 2) / 3)) N = N1 - (N2 * N3) + day - 30 return N I tried to port that into a Haskell. Like this: day_of_year year month day = n1 - (n2 * n3) + day - 30 where n1 = floor(275 * fromIntegral month / 9) n2 = floor( month + 9 / 12) n3 = 1 + floor((year - 4 * floor(fromIntegral year / 4) + 2) / 3) It doesn't work :( Here are my questions:

How can I toggle a boolean number?

雨燕双飞 提交于 2019-12-10 12:27:45
问题 Here is my code: $num = 1; // it always is either 0 or 1 if ( $num == 1 ){ $num = 0 } else { $num = 1; } As you see, my code toggles the number. It is really ugly to me. I guessed php should has a function to do so. But I didn't find anything similar after some searches. Anyway, can I do that more standard and better? Currectly I'm coding for a great company. That's why I want to write clean and professional codes. 回答1: Your approach is correct and will work as well. Just you need to wrap it