I can't get a decimal out of my equation. Trying to use progress bar












0















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.










share|improve this question




















  • 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
















0















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.










share|improve this question




















  • 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














0












0








0








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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














  • 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












2 Answers
2






active

oldest

votes


















0














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





share|improve this answer
























  • 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



















-1














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






share|improve this answer


























  • Those are still Int.

    – rmaddy
    Nov 26 '18 at 1:00











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
});


}
});














draft saved

draft discarded


















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









0














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





share|improve this answer
























  • 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
















0














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





share|improve this answer
























  • 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














0












0








0







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





share|improve this answer













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






share|improve this answer












share|improve this answer



share|improve this answer










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



















  • 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













-1














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






share|improve this answer


























  • Those are still Int.

    – rmaddy
    Nov 26 '18 at 1:00
















-1














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






share|improve this answer


























  • Those are still Int.

    – rmaddy
    Nov 26 '18 at 1:00














-1












-1








-1







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






share|improve this answer















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







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 26 '18 at 8:35

























answered Nov 25 '18 at 23:09









Jevon718Jevon718

749




749













  • Those are still Int.

    – 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





Those are still Int.

– rmaddy
Nov 26 '18 at 1:00


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks