number-formatting

Trying to format number to 2 decimal places jQuery [duplicate]

*爱你&永不变心* 提交于 2019-12-22 05:17:05
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: JavaScript: formatting number with exactly two decimals Getting a bit muddled up using variables and now cant seem to get calculation to work at all!? $("#discount").change(function(){ var list = $("#list").val(); var discount = $("#discount").val(); var price = $("#price"); var temp = discount * list; var temp1 = list - temp; var total = parseFloat($(this).temp1()).toFixed(2); price.val(total); }); 回答1: $(this)

Trying to format number to 2 decimal places jQuery [duplicate]

僤鯓⒐⒋嵵緔 提交于 2019-12-22 05:17:00
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: JavaScript: formatting number with exactly two decimals Getting a bit muddled up using variables and now cant seem to get calculation to work at all!? $("#discount").change(function(){ var list = $("#list").val(); var discount = $("#discount").val(); var price = $("#price"); var temp = discount * list; var temp1 = list - temp; var total = parseFloat($(this).temp1()).toFixed(2); price.val(total); }); 回答1: $(this)

Dart - NumberFormat

你说的曾经没有我的故事 提交于 2019-12-22 04:05:30
问题 Is there a way with NumberFormat to display : '15' if double value is 15.00 '15.50' if double value is 15.50 Thanks for your help. 回答1: Actually, I think it's easier to go with truncateToDouble() and toStringAsFixed() and not use NumberFormat at all: n.toStringAsFixed(n.truncateToDouble() == n ? 0 : 2); So for example: main() { double n1 = 15.00; double n2 = 15.50; print(format(n1)); print(format(n2)); } String format(double n) { return n.toStringAsFixed(n.truncateToDouble() == n ? 0 : 2); }

How to comma-separate numbers in EditText

允我心安 提交于 2019-12-21 20:45:51
问题 I have an EditText that has an inputType of number . While the user is typing, I want to comma-separate the numbers. Here's a little illustration: 123 would be represented as 123 1234 would be represented as 1,234 12345 would be represented as 12,345 ...and so on. I tried adding a comma with TextWatcher as shown below: EditText edittext = findViewById(R.id.cashGiven); edittext.addTextChangedListener(new TextWatcher(){ @Override public void beforeTextChanged(CharSequence charSequence, int i,

Add thousands separator to auto sum

筅森魡賤 提交于 2019-12-21 06:10:50
问题 I would like the sum calculated from the script below to display two decimals, and thousands separated by a comma. At this stage it only display the two decimals. I am new to programming and have tried various techniques but could not solve the problem. Below my JS code so far: function calculateSum() { var sum = 0; //iterate through each textboxes and add the values $(".txt").each(function() { //add only if the value is number if(!isNaN(this.value) && this.value.length!=0) { sum +=

Add thousands separator to auto sum

拜拜、爱过 提交于 2019-12-21 06:10:03
问题 I would like the sum calculated from the script below to display two decimals, and thousands separated by a comma. At this stage it only display the two decimals. I am new to programming and have tried various techniques but could not solve the problem. Below my JS code so far: function calculateSum() { var sum = 0; //iterate through each textboxes and add the values $(".txt").each(function() { //add only if the value is number if(!isNaN(this.value) && this.value.length!=0) { sum +=

What is the difference between %i and %d in Python? [duplicate]

空扰寡人 提交于 2019-12-20 20:02:21
问题 This question already has answers here : What is the difference between conversion specifiers %i and %d in formatted IO functions (*printf / *scanf) (4 answers) Closed 6 years ago . OK I was looking into number formatting and I found that you could use %d or %i to format an integer. For example: number = 8 print "your number is %i." % number or number = 8 print "your number is %d." % number But what is the difference? I mean i found something but it was total jibberish. Anyone speak Mild-Code

PHP - number_format and rounding

大城市里の小女人 提交于 2019-12-20 07:22:39
问题 The number_format function in PHP seems to round by default. My understanding is that this function is useful for separating every three numbers with a comma. Like 1403423 becomes 1,404,423 when using number_format. So, if I have a large number that I want rounded to two decimal places, how can I do this and still have the commas properly displayed? Desired behavior: 12042.529 --> 12,042.53 回答1: $a=12042.529; echo number_format($a,2,'.',','); 来源: https://stackoverflow.com/questions/19019409

DecimalFormat with RoundingMode.HALF_UP

僤鯓⒐⒋嵵緔 提交于 2019-12-20 04:25:28
问题 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 <--

Decimal point alignment in iOS UILabel during countdown?

一笑奈何 提交于 2019-12-20 04:23:40
问题 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! 回答1: I think your suggestion of multiple