Formatter black is not working on my VSCode…but why?

Update 2023-09-15: Now VSCode has a Microsoft oficial Black Formatter extension. It will probably solve your problems. Original answer: I use Black from inside VSCode and it rocks. It frees mental cycles that you would spend deciding how to format your code. It’s best to use it from your favorite editor. Just run from the … Read more

How to properly format currency on ios

You probably want something like this (assuming currency is a float): NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; [numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle]; NSString *numberAsString = [numberFormatter stringFromNumber:[NSNumber numberWithFloat:currency]]; From your requirements to treat 52 as .52 you may need to divide by 100.0. The nice thing about this approach is that it will respect the current locale. … Read more

Android NumberPicker with Formatter doesn’t format on first rendering

dgel’s solution doesn’t work for me: when I tap on the picker, formatting disappears again. This bug is caused by input filter set on EditText inside NumberPicker when setDisplayValues isn’t used. So I came up with this workaround: Field f = NumberPicker.class.getDeclaredField(“mInputText”); f.setAccessible(true); EditText inputText = (EditText)f.get(mPicker); inputText.setFilters(new InputFilter[0]);

Double parameter with 2 digits after dot in strings.xml?

Just adding to @David Airam’s answer here; the “incorrect” solution he gives is actually correct, but with a bit of tweaking. The XML file should contain: <string name=”resource1″>Hello string: %1$s, and hello float: %2$.2f.</string> Now in the Java code: String svalue = “test”; float sfloat= 3.1415926; String sresult = getString(R.string.resource1, svalue, sfloat); The exception that … Read more

How can I correctly format currency using jquery?

Another option (If you are using ASP.Net razor view) is, On your view you can do <div>@String.Format(“{0:C}”, Model.total)</div> This would format it correctly. note (item.total is double/decimal) if in jQuery you can also use Regex $(“.totalSum”).text(‘$’ + parseFloat(total, 10).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, “$1,”).toString());

datetime: Round/trim number of digits in microseconds

The simplest way would be to use slicing to just chop off the last three digits of the microseconds: def format_time(): t = datetime.datetime.now() s = t.strftime(‘%Y-%m-%d %H:%M:%S.%f’) return s[:-3] I strongly recommend just chopping. I once wrote some logging code that rounded the timestamps rather than chopping, and I found it actually kind of … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)