If I polymorph my ally into a giant ape(huge),how do you determine the exact height?
If you are not the DM, you don't. If you are the DM, you do it by saying "The Giant Ape is X feet tall", where X is whatever number you think is a fair thing.
In determining what a reasonable value for X is, the DM may want to look at the picture on page 248 of the DMG which suggests that anywhere from 15 to 25 feet might be appropriate. In my mind's eye Giant Ape = King Kong so I would head towards the upper end of the range so that it can comfortably fit a comely beauty (of either sex) in its hand while climbing the Empire State Building.
Exact sizes are not well-defined.
Not only is the height of a creature not delineated by its size, but its length and width aren't either. PHB 190 states,
A creature's space is the area in feet that it effectively controls in combat, not an expression of its physical dimensions.
For example, dwarves (as short as 4ft) and elves (as tall as 6+ ft) are both medium in size. In the absence of the detailed size information that was given in previous editions, it's up to the DM and the players to come to a workable physical size.
You probably have some control over the exact height.
The discussion in this question suggests that the caster of polymorph has some degree of control over the specifics of the new form. It's ultimately up to the DM to determine, but it seems like there's a lot of leeway inherent in the spell.