Results 1 to 5 of 5

Thread: Turning an integer or decimal number into a decimal in the tenths, hundredths, etc...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2016
    Posts
    95

    Turning an integer or decimal number into a decimal in the tenths, hundredths, etc...

    Hello! I am developing a program to help me do some stuff that isn't important. Anyways, I need a way to make say the number 5 into 0.5 or 05 into 0.05 or 5.31 into 0.531 | I have no idea how to do this. I am new to the language and learning everyway possible, all suggestions would be fantastic! Thanks!!!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Turning an integer or decimal number into a decimal in the tenths, hundredths, et

    That's not really a consistent requirement. You treat "5" and "05" differently, so how would you treat "05.31"?

    Anyway, I don't think you've really given this much thought. It's basically turning a String into number and performing a division, both of which are quite elementary operations.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2016
    Posts
    95

    Re: Turning an integer or decimal number into a decimal in the tenths, hundredths, et

    I know how to, I was hoping there would have been a way to do it exactly the way I want it to. I guess I can make a work around, I was just hoping it would simply detect it and convert it to 0.{number here}

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Turning an integer or decimal number into a decimal in the tenths, hundredths, et

    As I said, it's not a consistent requirement. If it was just integers then you could simply prepend "0." to the digits you have and then convert that to a Double but that's obviously not going to work for numbers that already have a decimal point. If you want to do different things based on certain criteria then you have to use an 'If' statement or the like. There's no single operator that will read your mind on this.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2016
    Posts
    95

    Re: Turning an integer or decimal number into a decimal in the tenths, hundredths, et

    I guess so haha, well thanks anyways man

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width