string-formatting

Convert basic script to Objective C (money formatting)

萝らか妹 提交于 2019-12-04 02:19:44
问题 I've got this basic like script that I need to convert to objective c, it turns big units of money into shortened versions (ie: 1.2m, etc), I've got most of the conversion done, but the biggest problem I'm having is right at the end. The original basic code is: ; Basic Code Function ShortCash$(BigNumber) out$="" ; First, grab the length of the number L=Len(BigNumber) Letter$="" ;Next, Do a sweep of the values, and cut them down. If l<13 out$=(BigNumber/1000000000) ; For each figure, out

How do I use TeX/LaTeX formatting for custom data tips in MATLAB?

只谈情不闲聊 提交于 2019-12-04 01:28:51
问题 I'm trying to annotate a polar plot with data tips labelled with 'R:...,Theta:...' where theta is actually the Greek symbol, rather than the word spelled out. I'm familiar with string formatting using '\theta' resulting in the symbol, but it doesn't work in this case. Is there a way to apply the LaTeX interpreter to data tips? Here's what I have so far: f1=figure; t=pi/4; r=1; polar(t,r,'.'); dcm_obj = datacursormode(f1); set(dcm_obj,'UpdateFcn',@polarlabel) info_struct = getCursorInfo(dcm

Converting MM:SS.ms to seconds using MS excel

ぃ、小莉子 提交于 2019-12-04 01:18:59
I am looking for a neat way of converting a cell from Minutes:Seconds.Milliseconds to Seconds.Milliseconds i.e. 11.111 = 11.111 1:11.111 = 71.111 I have something in place at the moment but its a bit hacky and I am sure there must be some nice excel feature to do this for me :P Thanks! Do this: Place values 0:0:11.111 and 0:1:11.111 in cells B3 and B4 respectively. Now format it to account for the milliseconds... Select cells B3 and B4 , right click and choose Format Cells. In Custom, put the following in the text box labeled Type : [h]:mm:ss.000 Now on cell C3 put the following formula: =B3

How do you format complex numbers for text output in matlab

一个人想着一个人 提交于 2019-12-04 00:52:09
问题 I have a complex number that I want to output as text using the fprintf command. I don't see a formatspec for complex numbers. Is there an easy way to do this? Using the format spec for fixed-point is only outputting the real part. 回答1: According to the documentation of fprintf and sprintf Numeric conversions print only the real component of complex numbers. So for a complex value z you can use this sprintf('%f + %fi\n', z, z/1i) for example >> z=2+3i; >> sprintf('%f + %fi\n', z, z/1i) 2

String.Format - How can I format to x digits (regardless of decimal place)?

流过昼夜 提交于 2019-12-04 00:38:35
I need to format a floating point number to x characters (6 in my case including the decimal point). My output also needs to include the sign of the number So given the inputs, here are the expected outputs 1.23456 => +1.2345 -12.34567 => -12.345 -0.123456 => -0.1234 1234.567 => +1234.5 Please assume there is always a decimal place before the last character. I.e. there will be no 12345.6 number input - the input will always be less than or equal to 9999.9 . I'm thinking this has to be done conditionally. Here's a transparent way to do it without format strings (except for "F"): static void

Format string template with variables in Javascript

别等时光非礼了梦想. 提交于 2019-12-03 23:48:01
I want to use a statically defined template for URL building. I'm trying to use ES6 string interpolation feature for this var template = "http://example.com/?name=${name}&age=${age}"; var name = "John"; var age = "30"; var url = `${template}`; Expected result: http://example.com/?name=John&age=23 Actual result: http://example.com/?name= ${name}&age=${age} In case this can't be done with string interpolation is there any better method than String.prototype.replace like var url = template.replace(/\${name}/,"John").replace(/\${age}/, 23); pawel The variables are substituted at the moment of

What is the easiest way to pad a string with 0 to the left?

岁酱吖の 提交于 2019-12-03 23:40:10
What is the easiest way to pad a string with 0 to the left so that "110" = "00000110" "11110000" = "11110000" I have tried to use the format! macro but it only pads to the right with space: format!("{:08}", string); Shepmaster The fmt module documentation describes all the formatting options: Fill / Alignment The fill character is provided normally in conjunction with the width parameter. This indicates that if the value being formatted is smaller than width some extra characters will be printed around it. The extra characters are specified by fill , and the alignment can be one of the

java String.format: numbers with localization

僤鯓⒐⒋嵵緔 提交于 2019-12-03 23:33:41
Is it possible to localize numbers in String.format call the same way as NumberFormat.format does? I've expected it simply to use String.format(locale, "%d", number) but this doesn't return the same result as if using NumberFormat. For example: String.format(Locale.GERMAN, "%d", 1234567890) gives: "1234567890", while NumberFormat.getNumberInstance(Locale.GERMAN).format(1234567890) gives: "1.234.567.890" If it can't be done, what's recommended way for localizing text including numbers? From the documentation , you have to: supply a locale (as you are doing in your example) include the ',' flag

printf for size_t

。_饼干妹妹 提交于 2019-12-03 23:32:11
Is there any way to give printf a size_t without either casting it first or generating a compiler warning? (I always compile with -Wall .) printf("%zu", sizeof(whatever)); 来源: https://stackoverflow.com/questions/4150056/printf-for-size-t

C# How to format a double to one decimal place without rounding

丶灬走出姿态 提交于 2019-12-03 22:27:42
I need to format a double value to one decimal place without it rounding. double value = 3.984568438706 string result = ""; What I have tried is: 1) result = value.ToString("##.##", System.Globalization.CultureInfo.InvariantCulture) + "%"; // returns 3.98% 2) result = value.ToString("##.#", System.Globalization.CultureInfo.InvariantCulture) + "%"; // returns 4% 3) result = value.ToString("##.0", System.Globalization.CultureInfo.InvariantCulture) + "%"; // returns 4.0% 4) (Following other suggestions) value = (value / 100); result = String.Format("{0:P1}", Math.Truncate(value * 10000) / 10000);