number-formatting

Decimal point alignment in iOS UILabel during countdown?

独自空忆成欢 提交于 2019-12-02 04:07:05
Sorry I don't have any code yet, but would appreciate some advice! I have a countdown timer showing seconds with one decimal point in a UILabel (10.0, 9.9, 9.8, etc.). It works fine, but the decimal point moves around slightly depending on the size decimal value. Is there a way to align the text in the UILabel to the decimal point or should I create two labels (one for the seconds value aligned right and one for the decimal value aligned left)? Thanks! I think your suggestion of multiple labels is perfectly valid. Here is an attributed string solution (for m:ss but it should work with floating

convert 10 digit number to hex string

大城市里の小女人 提交于 2019-12-02 03:22:26
问题 How do I convert a 10 digit number to a hex string in c#? Note : if the number is less than 10 digits, I want to add padding? example the number is 1, I want my string to be 0000000001. 回答1: Use a standard format string: string paddedHex = myNumber.ToString("x10"); See the x format specifier. 来源: https://stackoverflow.com/questions/4416974/convert-10-digit-number-to-hex-string

DecimalFormat with RoundingMode.HALF_UP

大城市里の小女人 提交于 2019-12-02 03:02:30
Having a simple code import java.math.RoundingMode import java.text.DecimalFormat fun main(args: Array<String>) { val f = DecimalFormat("#.##").apply { roundingMode = RoundingMode.HALF_UP } println(f.format(-0.025f)) println(f.format(-0.015f)) println(f.format(-0.005f)) println(f.format(0.005f)) println(f.format(0.015f)) println(f.format(0.025f)) } I got the following output: -0,03 <-- ok -0,01 <-- expecting -0,02 -0 <-- expecting -0,01 0 <-- expecting 0,01 0,01 <--- expecting 0,02 0,03 <-- ok Do I correctly understand RoundingMode.HALF_UP meaning? P.S. I had found, that using doubles instead

Can I set the decimal symbol to use everywhere in my application

走远了吗. 提交于 2019-12-02 01:39:25
I tracked down a bug in my application that occurred for people in countries where the default decimal symbol was a comma instead of a period. Is there any way in C# to set the decimal symbol for my application without affecting other apps or permanently changing the system settings? I tried this but it says the NumberDecimalSeparator is readonly. Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator = "."; I you still need to do that you can change the CurrentCulture on the thread like so: Thread.CurrentThread.CurrentCulture = new CultureInfo("en-Us"); Chooe a Culture that

pad numeric column with leading zeros

前提是你 提交于 2019-12-02 00:50:03
问题 I've been looking into this for the past few hours. I have tried using sprintf but it changes the column to character. All I want to do is to have a fixed-width numeric column, padded with zeros. 回答1: If you're willing to use a custom class, you can write a print method that does this. Make a data frame, and give it a custom class: DF <- data.frame(a=letters[1:10], b=sample(c(1, 10, 100), 10, rep=T), c=sample(c(1, 10, 100), 10, rep=T)) class(DF) <- c("my_df", class(DF)) Write a print method

pad numeric column with leading zeros

核能气质少年 提交于 2019-12-01 23:05:14
I've been looking into this for the past few hours. I have tried using sprintf but it changes the column to character. All I want to do is to have a fixed-width numeric column, padded with zeros. If you're willing to use a custom class, you can write a print method that does this. Make a data frame, and give it a custom class: DF <- data.frame(a=letters[1:10], b=sample(c(1, 10, 100), 10, rep=T), c=sample(c(1, 10, 100), 10, rep=T)) class(DF) <- c("my_df", class(DF)) Write a print method that uses @BenBolker's formatting: print.my_df <- function(x, ...) { num.cols <- sapply(x, is.numeric) x[num

Haskell - how to avoid scientific notation in decimal output

核能气质少年 提交于 2019-12-01 22:39:05
I need to divide a list of numbers by 100 to be printed, for example: map (/100) [29, 3, 12] produces: [0.29,3.0e-2,0.12] however I need: [0.29,0.03,0.12] How do I do this in Haskell? Any ideas really appreciated. 0.03 and 3.0e-2 are the same number. Internally, GHC uses showFloat to print it, which will result in the scientific notation whenever the absolute value is outside the range 0.1 and 9,999,999. Therfore, you have to print the values yourself, for example with printf from Text.Printf or showFFloat from Numeric : import Numeric showFullPrecision :: Double -> String showFullPrecision x

Matlab, how to adjust axis values on figures (scientific notaiton - not enough precision) [duplicate]

无人久伴 提交于 2019-12-01 20:15:13
Possible Duplicate: Suppress exponential formatting in figure ticks Matlab is outputting my axis markers as 5.777 x10^6 for every tick mark in my figures... is it possible to get matlab to output the actual decimal number rather than scientific notation so the tick marks are actually different values rather than all 5.777? Currently I don't really know where in space these plots are because of a lack of precision on the axis. One possible solution: plot(rand(100,1).*1e6) set(gca, 'YTickLabel', num2str(get(gca,'YTick')','%d')) Obviously you can customize the formatting to your liking Another

PHP, Format Number to have always have 2 decimal places

孤街浪徒 提交于 2019-12-01 17:27:17
In PHP I have decimal numbers that may or may not have trailing zeros. For example 1 1.1 43.87 How do I make sure that all these numbers have exactly two decimal places like this: 1.00 1.10 43.87 You should use number_format() : number_format(1.1, 2); 来源: https://stackoverflow.com/questions/18898638/php-format-number-to-have-always-have-2-decimal-places

Why did MATLAB delete my decimals?

怎甘沉沦 提交于 2019-12-01 16:58:51
Let's say I create some number A , of the order 10^4 : A = 81472.368639; disp(A) 8.1472e+04 That wasn't what I wanted. Where are my decimals? There should be six decimals more. Checking the variable editor shows me this: Again, I lost my decimals. How do I keep these for further calculations? Scientific notation, or why you didn't lose any decimals You didn't lose any decimals, this is just MATLAB's way of displaying large numbers. MATLAB rounds the display of numbers, both in the command window and in the variable editor, to one digit before the dot and four after that, using scientific