Results 1 to 18 of 18

Thread: Number formatting (0.5 -> 1/2)

  1. #1

    Thread Starter
    Member
    Join Date
    May 2002
    Posts
    51

    Number formatting (0.5 -> 1/2)

    Is it possible to set the formatting of a number to display, for example, 10 1/2 (and 1/2 is written in "normal" style, you know, 1 over 2 in smaller font) as opposed to 10.5?

  2. #2
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    I seriously doubt it since what you're asking for is NOT a font but a whole parsing algorithm. It's possible that someone has subclassed a font to do that work behind the scenes but it would be so inherently limited that it's just as likely that no one has bothered. Figuring out how to construct a web search for what you want would be an interesting exercise all by itself. good luck.

  3. #3
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    It is possible, however some parsing will definately be involved. You will need to find a decimal point which isn't the same in different parts of this world, then you will nedd identify if it is a half (may be some rounding routine is necessary) and only when it is finally identified as "ONE HALF" you may use Replace function (in VB6 only otherwise Mid) to replace what's after decimal point with ASCII charachter 189 [Chr(189); True fonts only] . Is it worth it - I don't think so!

    Roy

  4. #4
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    You could convert 10.5 to 10 1/2 fairly easily. And most fonts have the 1/2 symbol.

  5. #5
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    If 1/2 is the ONLY fraction you want then it's easy. My reply was based on the assumption (apparently not shared by the other respondents) that you want a generic solution, not just for the particular example of 1/2

  6. #6
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    What you'd do to get a fraction from the decimal is this:

    Convert the decimal number to a non-decimal number, store the value needed to do this.

    Then it's number/store value. to do this you're going to have to see how many of the stored values * x = big number without going over. then subtract the number by that value. Then reduce the fraction by checking the number and the stored number for like multiples.

  7. #7

    Thread Starter
    Member
    Join Date
    May 2002
    Posts
    51
    Yes, I am looking for 1/2 only.

  8. #8
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    ½

    there's also

    ¼¾

    you could do:

    if right("10.5",2) = ".5" then msgbox replace("10.5",".5","½")
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  9. #9

    Thread Starter
    Member
    Join Date
    May 2002
    Posts
    51
    That looks like what I need. How do you get the fraction to replace .5 as opposed to 1/2?

  10. #10
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    waht do you mean?
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  11. #11
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    If instr(num,".5") > 0 then num = replace(num, ".5", " 1/2")

  12. #12

    Thread Starter
    Member
    Join Date
    May 2002
    Posts
    51
    Sorry...I want to use the "normal" looking fraction (1 over 2, and a smaller font...as you did in your previous posting) as opposed to "1/2". I could live with either way, I was just wondering how to do it.

  13. #13
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    So replace my 1/2 with a copy/paste of the other 1/2.

  14. #14
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    i already gave you the way to do it:

    if right("10.5",2) = ".5" then msgbox replace("10.5",".5","½")
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  15. #15
    Hyperactive Member
    Join Date
    Jun 2002
    Posts
    299
    Actually, just get the length of the string to the right of the decimal place, and put that over 10^(Len). Then write a simplify function. Simple really.

  16. #16
    Lively Member
    Join Date
    Jan 2002
    Location
    ...Wherever God wants me...
    Posts
    125
    What character code is that li'l "1/2" that you put in there?
    to the power of X

  17. #17
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    Doesn'y anybody read? It says in one of the first few posts that ASCII 189 is the ½ character...

    ASCII charachter 189 [Chr(189); True fonts only]
    <removed by admin>

  18. #18
    Lively Member
    Join Date
    Jan 2002
    Location
    ...Wherever God wants me...
    Posts
    125
    lol... missed it, thanks
    to the power of X

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