numbers

How do I format a number with commas?

一曲冷凌霜 提交于 2019-12-03 09:36:40
int a = 10000000; a.ToString(); How do I make the output? 10,000,000 Try N0 for no decimal part: string formatted = a.ToString("N0"); // 10,000,000 You can also do String.Format: int x = 100000; string y = string.Empty; y = string.Format("{0:#,##0.##}", x); //Will output: 100,000 If you have decimal, the same code will output 2 decimal places: double x = 100000.2333; string y = string.Empty; y = string.Format("{0:#,##0.##}", x); //Will output: 100,000.23 To make comma instead of decimal use this: double x = 100000.2333; string y = string.Empty; y = string.Format(System.Globalization

How does “+var === +var” work internally to verify if var is numeric?

北城余情 提交于 2019-12-03 09:18:24
Seeing this question: Is there a (built-in) way in JavaScript to check if a string is a valid number? and this: jsperf , one of the presented approaches is this (mutatis mutandis): var a = "123" var b = "123b" if ( +a === +a ) // true if ( +b === +b ) // false How does this logic work internally in JavaScript to make this possible? My question is not how to check if a string is a valid number – this is already answered here: Validate decimal numbers in JavaScript - IsNumeric() . I want to understand how the statement +a === +a works. + converts the value to a number. a gets converted to 123

Cannot read property 'toUpperCase' of undefined (“<input name= ”searchtext“ [(ngModel)]=”searchtext\">

匿名 (未验证) 提交于 2019-12-03 09:02:45
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to do filter a number from a number array. but I got this errors.this a my codes. app.module.ts import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { NumberFilterPipe } from './number-filter.pipe'; import { FormsModule } from '@angular/forms'; import { StringFilterPipe } from './string-filter.pipe'; import { NumberFilterService } from './service/number-filter.service'; @NgModule({ declarations: [ AppComponent, NumberFilterPipe,

How to stop a setTimeout loop?

匿名 (未验证) 提交于 2019-12-03 08:59:04
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to build a loading indicator with a image sprite and I came up with this function function setBgPosition() { var c = 0; var numbers = [0, -120, -240, -360, -480, -600, -720]; function run() { Ext.get('common-spinner').setStyle('background-position', numbers[c++] + 'px 0px'); if (c so the out put is looks like this http://jsfiddle.net/TTkre/ I had to use setBgPosition(); inside else to keep this running in a loop so now my problem is how to stop this loop once I want [load finished]? 回答1: setTimeout returns a timer handle, which

Swift number formatting

我的梦境 提交于 2019-12-03 08:02:42
I am just starting to get to know Swift but I am having a serious problem with number formatting at an extremely basic level. For example, I need to display an integer with at least 2 digits (e.g. 00, 01, 02, 03, 04, 05 ...). The normal syntax I'd expect would be something like: println(" %02i %02i %02i", var1, var2, var3); ...but I don't find any clear instruction for how to achieve this in Swift. I find it really hard to believe that I need to create a custom function to do that. The same for returning a float or double value to a fixed number of decimal places. I've found links to a couple

How to show number of a line in a RichTextBox C#

这一生的挚爱 提交于 2019-12-03 07:32:38
问题 I am making a simple text and script editor with code highlighting. For that I use a RichTextBox. But I don't know how to make it show the lines' numbers on the left side, like in VS or Notepad++. Is there any solution? 回答1: I tried re-using the code from the codeproject articles referenced elsewhere, but every option I looked at, seemed a bit too kludgy. So I built another RichTextBoxEx that displays line numbers. The line numbering can be turned on or off. It's fast. It scrolls cleanly. You

Convert a number from Base B1 to Base B2 without using any intermediate base

百般思念 提交于 2019-12-03 07:13:12
问题 Is there a way Convert a number from Base B1 to Base B2 without using any intermediate base. Ex: 214 from base 5 to base 16 without converting it first to decimal and then decimal to hexadecimal. -- Thanks Alok Kr. 回答1: To convert 214 base5 to base 16 without an intermediate base, you "just" have to know how to calculate directly in base 5. First, you need a table of what the base 16 digits are in base 5 (you need a similar table when converting base 10 to base 16, it's just that that one is

Python - Check if the last characters in a string are numbers

瘦欲@ 提交于 2019-12-03 06:30:56
问题 Basically I want to know how I would do this. Here's an example string: string = "hello123" I would like to know how I would check if the string ends in a number, then print the number the string ends in. I know for this certain string you could use regex to determine if it ends with a number then use string[:] to select "123". BUT if I am looping through a file with strings like this: hello123 hello12324 hello12435436346 ...Then I will be unable to select the number using string[:] due to

What type would you map BigDecimal in Java/Hibernate in MySQL?

落爺英雄遲暮 提交于 2019-12-03 06:30:34
问题 After going through the previous develop's trainwreck of code I realized I need to move all of the money based columns to not use floating point math. On the Java side this means using BigDecimal but when using Hibernate/JPA and MySQL 5 what would be the appropriate MySQL data type to make that column? 回答1: DECIMAL and NUMERIC. The recommended Java mapping for the DECIMAL and NUMERIC types is java.math.BigDecimal. The java.math.BigDecimal type provides math operations to allow BigDecimal

Why does double in C print fewer decimal digits than C++?

北战南征 提交于 2019-12-03 06:28:14
问题 I have this code in C where I've declared 0.1 as double. #include <stdio.h> int main() { double a = 0.1; printf("a is %0.56f\n", a); return 0; } This is what it prints, a is 0.10000000000000001000000000000000000000000000000000000000 Same code in C++, #include <iostream> using namespace std; int main() { double a = 0.1; printf("a is %0.56f\n", a); return 0; } This is what it prints, a is 0.1000000000000000055511151231257827021181583404541015625 What is the difference? When I read both are