|
|
|
iOS - (มือใหม่)ทำไมค่า float ที่ดึงออกมาจากไฟล์ php หลังทศนิยมเป็น 00000 |
|
|
|
|
|
|
|
ตอนที่ echo ค่าใน JSON จาก php มันมีมาให้หรือเปล่าครับ หรือไม่ก็ Convert ให้เป็น int (จำนวนเต็มก็ได้ครับ)
Code (Objective-C)
double myDouble = 3.2;
int myInt = (int)myDouble;
|
|
|
|
|
Date :
2013-08-19 09:24:20 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมว่าไปทำที่ตัว php น่าจะ่ง่ายกว่านะพอมาที่ app จะได้เรียกใช้ได้เลย หรือถ้าไม่งั้นก็ลองดูที่นี้ก็ได้ครับ
Code
float numberToRound;
int result;
numberToRound = 4.51;
result = (int)roundf(numberToRound);
NSLog(@"roundf(%f) = %d", numberToRound, result); // roundf(4.510000) = 5
result = (int)ceilf(numberToRound);
NSLog(@"ceilf(%f) = %d", numberToRound, result); // ceilf(4.510000) = 5
result = (int)floorf(numberToRound);
NSLog(@"floorf(%f) = %d", numberToRound, result); // floorf(4.510000) = 4
numberToRound = 10.49;
result = (int)roundf(numberToRound);
NSLog(@"roundf(%f) = %d", numberToRound, result); // roundf(10.490000) = 10
result = (int)ceilf(numberToRound);
NSLog(@"ceilf(%f) = %d", numberToRound, result); // ceilf(10.490000) = 11
result = (int)floorf(numberToRound);
NSLog(@"floorf(%f) = %d", numberToRound, result); // floorf(10.490000) = 10
numberToRound = -2.49;
result = (int)roundf(numberToRound);
NSLog(@"roundf(%f) = %d", numberToRound, result); // roundf(-2.490000) = -2
result = (int)ceilf(numberToRound);
NSLog(@"ceilf(%f) = %d", numberToRound, result); // ceilf(-2.490000) = -2
result = (int)floorf(numberToRound);
NSLog(@"floorf(%f) = %d", numberToRound, result); // floorf(-2.490000) = -3
numberToRound = -3.51;
result = (int)roundf(numberToRound);
NSLog(@"roundf(%f) = %d", numberToRound, result); // roundf(-3.510000) = -4
result = (int)ceilf(numberToRound);
NSLog(@"ceilf(%f) = %d", numberToRound, result); // ceilf(-3.510000) = -3
result = (int)floorf(numberToRound);
NSLog(@"floorf(%f) = %d", numberToRound, result); // floorf(-3.510000) = -4
hxxps://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/Classes/NSNumber_Class/Reference/Reference.html
|
|
|
|
|
Date :
2013-08-20 10:18:37 |
By :
phpbasic |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|