I can't get a decimal out of my equation. Trying to use progress bar
I'm using a progress bar in my app to show how close someone is to reaching their savings goal. Here are my variables: (Note they are supposed to be in dollars.)
var amountToSave: Int = 100
var amountSavedSoFar: Int = 10
I've tried many equations that should work, but they either put out zero or over 1 which makes the progress bar go full. Here are some that I have tried:
var progress: Int = amountSavedSoFar/AmountToSave //puts out zero (should be 0.10)
I've also tried:
var progress: Int = 100*amountSavedSoFar/amountToSave //puts out over 1 (Progress Bar goes full)
Am I missing something? I tried the math outside xcode on a calculator and the first one I tried should be the one that works. Thanks in advance.
swift progress-bar
add a comment |
I'm using a progress bar in my app to show how close someone is to reaching their savings goal. Here are my variables: (Note they are supposed to be in dollars.)
var amountToSave: Int = 100
var amountSavedSoFar: Int = 10
I've tried many equations that should work, but they either put out zero or over 1 which makes the progress bar go full. Here are some that I have tried:
var progress: Int = amountSavedSoFar/AmountToSave //puts out zero (should be 0.10)
I've also tried:
var progress: Int = 100*amountSavedSoFar/amountToSave //puts out over 1 (Progress Bar goes full)
Am I missing something? I tried the math outside xcode on a calculator and the first one I tried should be the one that works. Thanks in advance.
swift progress-bar
1
Possible duplicate of Math divison in Swift
– rmaddy
Nov 26 '18 at 1:02
0.1 isn't an integer. Why are you assigning it to an integer if you want it to be a floating point value?
– Rob Napier
Nov 26 '18 at 1:09
add a comment |
I'm using a progress bar in my app to show how close someone is to reaching their savings goal. Here are my variables: (Note they are supposed to be in dollars.)
var amountToSave: Int = 100
var amountSavedSoFar: Int = 10
I've tried many equations that should work, but they either put out zero or over 1 which makes the progress bar go full. Here are some that I have tried:
var progress: Int = amountSavedSoFar/AmountToSave //puts out zero (should be 0.10)
I've also tried:
var progress: Int = 100*amountSavedSoFar/amountToSave //puts out over 1 (Progress Bar goes full)
Am I missing something? I tried the math outside xcode on a calculator and the first one I tried should be the one that works. Thanks in advance.
swift progress-bar
I'm using a progress bar in my app to show how close someone is to reaching their savings goal. Here are my variables: (Note they are supposed to be in dollars.)
var amountToSave: Int = 100
var amountSavedSoFar: Int = 10
I've tried many equations that should work, but they either put out zero or over 1 which makes the progress bar go full. Here are some that I have tried:
var progress: Int = amountSavedSoFar/AmountToSave //puts out zero (should be 0.10)
I've also tried:
var progress: Int = 100*amountSavedSoFar/amountToSave //puts out over 1 (Progress Bar goes full)
Am I missing something? I tried the math outside xcode on a calculator and the first one I tried should be the one that works. Thanks in advance.
swift progress-bar
swift progress-bar
edited Nov 26 '18 at 1:00
rmaddy
242k27316380
242k27316380
asked Nov 25 '18 at 21:28
EvanEvan
14
14
1
Possible duplicate of Math divison in Swift
– rmaddy
Nov 26 '18 at 1:02
0.1 isn't an integer. Why are you assigning it to an integer if you want it to be a floating point value?
– Rob Napier
Nov 26 '18 at 1:09
add a comment |
1
Possible duplicate of Math divison in Swift
– rmaddy
Nov 26 '18 at 1:02
0.1 isn't an integer. Why are you assigning it to an integer if you want it to be a floating point value?
– Rob Napier
Nov 26 '18 at 1:09
1
1
Possible duplicate of Math divison in Swift
– rmaddy
Nov 26 '18 at 1:02
Possible duplicate of Math divison in Swift
– rmaddy
Nov 26 '18 at 1:02
0.1 isn't an integer. Why are you assigning it to an integer if you want it to be a floating point value?
– Rob Napier
Nov 26 '18 at 1:09
0.1 isn't an integer. Why are you assigning it to an integer if you want it to be a floating point value?
– Rob Napier
Nov 26 '18 at 1:09
add a comment |
2 Answers
2
active
oldest
votes
When you use Int , the result is Int
So you should use Double
var amountToSave: Double = 100.0
var amountSavedSoFar: Double = 10.0
var progress: Double = amountSavedSoFar/amountToSave
print(progress) //0.1
There's no need for the: Double
on the three variables.
– rmaddy
Nov 26 '18 at 17:19
Yeah, that seemed to work!
– Evan
Nov 27 '18 at 1:55
add a comment |
Make it a double
var amountToSave: = 100.0
var amountSavedSoFar: = 10.0
Also, I would suggest using a cocoa pod called "Money"
https://github.com/danthorpe/Money
Those are stillInt
.
– rmaddy
Nov 26 '18 at 1:00
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53472186%2fi-cant-get-a-decimal-out-of-my-equation-trying-to-use-progress-bar%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
When you use Int , the result is Int
So you should use Double
var amountToSave: Double = 100.0
var amountSavedSoFar: Double = 10.0
var progress: Double = amountSavedSoFar/amountToSave
print(progress) //0.1
There's no need for the: Double
on the three variables.
– rmaddy
Nov 26 '18 at 17:19
Yeah, that seemed to work!
– Evan
Nov 27 '18 at 1:55
add a comment |
When you use Int , the result is Int
So you should use Double
var amountToSave: Double = 100.0
var amountSavedSoFar: Double = 10.0
var progress: Double = amountSavedSoFar/amountToSave
print(progress) //0.1
There's no need for the: Double
on the three variables.
– rmaddy
Nov 26 '18 at 17:19
Yeah, that seemed to work!
– Evan
Nov 27 '18 at 1:55
add a comment |
When you use Int , the result is Int
So you should use Double
var amountToSave: Double = 100.0
var amountSavedSoFar: Double = 10.0
var progress: Double = amountSavedSoFar/amountToSave
print(progress) //0.1
When you use Int , the result is Int
So you should use Double
var amountToSave: Double = 100.0
var amountSavedSoFar: Double = 10.0
var progress: Double = amountSavedSoFar/amountToSave
print(progress) //0.1
answered Nov 26 '18 at 9:07
aminamin
14210
14210
There's no need for the: Double
on the three variables.
– rmaddy
Nov 26 '18 at 17:19
Yeah, that seemed to work!
– Evan
Nov 27 '18 at 1:55
add a comment |
There's no need for the: Double
on the three variables.
– rmaddy
Nov 26 '18 at 17:19
Yeah, that seemed to work!
– Evan
Nov 27 '18 at 1:55
There's no need for the
: Double
on the three variables.– rmaddy
Nov 26 '18 at 17:19
There's no need for the
: Double
on the three variables.– rmaddy
Nov 26 '18 at 17:19
Yeah, that seemed to work!
– Evan
Nov 27 '18 at 1:55
Yeah, that seemed to work!
– Evan
Nov 27 '18 at 1:55
add a comment |
Make it a double
var amountToSave: = 100.0
var amountSavedSoFar: = 10.0
Also, I would suggest using a cocoa pod called "Money"
https://github.com/danthorpe/Money
Those are stillInt
.
– rmaddy
Nov 26 '18 at 1:00
add a comment |
Make it a double
var amountToSave: = 100.0
var amountSavedSoFar: = 10.0
Also, I would suggest using a cocoa pod called "Money"
https://github.com/danthorpe/Money
Those are stillInt
.
– rmaddy
Nov 26 '18 at 1:00
add a comment |
Make it a double
var amountToSave: = 100.0
var amountSavedSoFar: = 10.0
Also, I would suggest using a cocoa pod called "Money"
https://github.com/danthorpe/Money
Make it a double
var amountToSave: = 100.0
var amountSavedSoFar: = 10.0
Also, I would suggest using a cocoa pod called "Money"
https://github.com/danthorpe/Money
edited Nov 26 '18 at 8:35
answered Nov 25 '18 at 23:09
Jevon718Jevon718
749
749
Those are stillInt
.
– rmaddy
Nov 26 '18 at 1:00
add a comment |
Those are stillInt
.
– rmaddy
Nov 26 '18 at 1:00
Those are still
Int
.– rmaddy
Nov 26 '18 at 1:00
Those are still
Int
.– rmaddy
Nov 26 '18 at 1:00
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53472186%2fi-cant-get-a-decimal-out-of-my-equation-trying-to-use-progress-bar%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Possible duplicate of Math divison in Swift
– rmaddy
Nov 26 '18 at 1:02
0.1 isn't an integer. Why are you assigning it to an integer if you want it to be a floating point value?
– Rob Napier
Nov 26 '18 at 1:09