format

javascript format price

房东的猫 提交于 2019-12-07 11:45:10
问题 I wish to format a variable to a price format where if it is for example $90 then leave out the decimal which it already does anyway. But if the value is $44.5 then I want to format it as $44.50. I can do it in php not javascript. PHP example: number_format($price, !($price == (int)$price) * 2); The code I want to format: $(showdiv+' .calc_price span').html(sum_price); 回答1: var price = 44.5; var dplaces = price == parseInt(price, 10) ? 0 : 2; price = '$' + price.toFixed(dplaces); 回答2: PHPJS

Fixed length of month and day in date format?

谁说我不能喝 提交于 2019-12-07 08:22:16
问题 Is there any way to format Date object to made fixed length of Day and Month in order to have good alignment in a column? For example: 15 May 2010 10 January 2010 Instead of 15 May 2010 10 January 2010 Thanks! 回答1: Have a look at the java.util.Formatter class whose format method is the same as String.format(...) and similar to System.out.printf. For example: import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class FormatDateCalendar { public static

Convert numpy array of RGB values to hex using format operator %

∥☆過路亽.° 提交于 2019-12-07 07:36:06
问题 Following on this SO question what would be the best way to use the formatting operator to apply it to a numpy array where the array is of the format given below corresponding to RGB values Note RGB values have been scaled 0 to 1 so multiple by 255 to rescale array([[ 0.40929448, 0.47071505, 0.27701891], [ 0.59383913, 0.60611158, 0.55329837], [ 0.4393785 , 0.4276561 , 0.34999225], [ 0.4159481 , 0.4516056 , 0.3026519 ], [ 0.54449997, 0.36963636, 0.4001209 ], [ 0.36970012, 0.3145826 , 0.315974

Format a local date at another time zone

落爺英雄遲暮 提交于 2019-12-07 07:33:48
问题 I try to format the current time in 2 locations: Chicago and Tokyo LocalDateTime now = LocalDateTime.now(); ZonedDateTime chicago = now.atZone(ZoneId.of("America/New_York")); System.out.println("chicago: " + chicago); System.out.println("Chicago formated: " + chicago.format(DateTimeFormatter.ofLocalizedTime(FormatStyle.FULL))); ZonedDateTime tokyo = now.atZone(ZoneId.of("Asia/Tokyo")); System.out.println("Tokyo: " + tokyo); System.out.println("Tokyo formated: " + tokyo.format

Reading format in Fortran 90

人盡茶涼 提交于 2019-12-07 07:14:57
问题 I have a huge file to read whose structure is: [...] (0,0,0,0,0): 5.00634e-33, 5.59393e-33, 6.24691e-33, 7.29338e-33, (0,0,0,0,4): 7.77607e-33, 8.95879e-33, 9.65316e-33, 1.07434e-32, (0,0,0,0,8): 1.20824e-32, 1.34983e-32, 1.49877e-32, 1.73061e-32, (0,0,0,0,12): 1.919e-32, 2.15391e-32, 2.3996e-32, 2.67899e-32, [...] I'm interested in reading the value after ":", which format should I use in the read statement if I use Fortran90? I've tried with read(1,'("(",I6,",",I6,",",I6,",",I6,",",I6,"):"

PHPExcel, Date being parsed incorrectly

我们两清 提交于 2019-12-07 05:56:20
问题 Currently, I'm making a program for my job that uses PHPexcel to basically take all of the data from an excel sheet, make a new excel sheet and format it to text, and transfer all of the data from the old excel sheet. My php has to be able to take in the values from the old excel sheet and parse them correctly, especially dates/numbers/etc. Everything is working fine except for the dates. For some reason when I get the formatted value of the cell; it does not match the date format in the

Postgres format string using array

元气小坏坏 提交于 2019-12-07 05:06:27
问题 I'm looking for an easy way to format a string using an array, like so: select format_using_array('Hello %s and %s', ARRAY['Jane', 'Joe']); format_using_array -------------------- Hello Jane and Joe (1 row) There's a format function but it needs explicit arguments and I don't know how many items are there in the array. I came up with a function like that: CREATE FUNCTION format_using_array(fmt text, arr anyarray) RETURNS text LANGUAGE plpgsql AS $$ declare t text; length integer; begin length

Get the given date format (the string specifying the format) in javascript or momentjs

怎甘沉沦 提交于 2019-12-07 04:46:36
问题 Given a datestring, how can I get the format string describing that datestring? Put another way, how can I get the format string that Date() or MomentJS (might be different for each, that's fine) would use to parse that datestring if one didn't pass an explicit format to use? So given '2016-01-01' it should output something like 'YYYY-MM-DD' , for example. (I am aware this is a simple question and may have an answer somewhere, but it is difficult to word concisely, so I could only find

PHPWord how to add text break / new line while in a text run

北战南征 提交于 2019-12-07 04:35:44
问题 How can I add a text break or go to the next line/row while in a text run? I tried to just do $section->addTextBreak(2); while in the text run but it just added the breaks to the section after the text run. I also tried $textrun->addTextBreak(2); but it gave me a fatal error. Any responses would be greatly appreciated. 回答1: I'm afraid that this will not be possible with current version. I don't have deep understanding of this library, but from looking at the code, I found out that the textRun

Can generators be used with string.format in python?

南楼画角 提交于 2019-12-07 03:41:42
问题 "{}, {}, {}".format(*(1,2,3,4,5)) Prints: '1, 2, 3' This works, as long as the number of {} in format does not exceed the length of a tuple. I want to make it work for a tuple of arbitrary length, padding it with - s if it is of insufficient length. And to avoid making assumptions about the number of {} 's, I wanted to use a generator. Here's what I had in mind: def tup(*args): for s in itertools.chain(args, itertools.repeat('-')): yield s print "{}, {}, {}".format(*tup(1,2)) Expected: '1, 2,